Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Doubt in grep command

+8
akalya
hansi
Nazneennazim
SakeenaHarris
anand
Christopher
Maithreyi
lalitha
12 posters

Page 2 of 3 Previous  1, 2, 3  Next

Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Mon Mar 15, 2010 5:07 pm

simply use,

Code:
grep j <filename>


600 th POST IN UNIX cheers cheers cheers


Last edited by Christopher on Mon Mar 15, 2010 5:09 pm; edited 1 time in total
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Vineet_More Mon Mar 15, 2010 5:08 pm

Well ou can use jj* also

Vineet_More

Posts : 27
Points : 31
Join date : 2010-02-26

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Saradha Kannan Tue Mar 16, 2010 2:10 pm

$cat s2.txt
sara
pree
saran
sowmini
sasi

$grep [^s] s2.txt
s2.txt:saran
s2.txt:sowmini

$grep [^abcd] s2.txt
s2.txt:saran
s2.txt:sowmini

$ grep [!s] s2.txt
s2.txt:saran
s2.txt:sowmini

$ grep [^s] s2.txt
s2.txt:saran
s2.txt:sowmini

What exactly is happening? Can someone help me out pls?

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Tue Mar 16, 2010 2:19 pm

'^' doesn't have any significance if it s not enclosed in single quotes.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Saradha Kannan Tue Mar 16, 2010 3:27 pm

grep ['^abcd'] s2.txt
sara
pree
saran
sowmini
sasi
[335908@oracleclient ~]$ grep '[^abcd]' s2.txt
sara
pree
saran
sowmini
sasi
[335908@oracleclient ~]$ grep ['^'abcd] s2.txtsara
pree
saran
sowmini
sasi

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Tue Mar 16, 2010 3:33 pm

if '^' is not enclosed within single quotes, it ll be considered as any other characer.
everything is working fine... do u have any problem with ur output?
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Tue Mar 16, 2010 4:43 pm

use single quotes outside square bracket. still u may not notice any difference for this example. try some other example.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Saradha Kannan Tue Mar 16, 2010 4:44 pm

Ok Thank you:)

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Vineet_More Tue Mar 16, 2010 4:47 pm

grep ['^abcd'] s2.txt
sara
pree
saran
sowmini
sasi
[335908@oracleclient ~]$ grep '[^abcd]' s2.txt
sara
saran
sasi
[335908@oracleclient ~]$ grep ['^'abcd] s2.txt
sara
pree
saran
sowmini
sasi
wat is happening in the second and third case?

Vineet_More

Posts : 27
Points : 31
Join date : 2010-02-26

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Maithreyi Tue Mar 16, 2010 4:57 pm

In the second case, '^abcd' denotes the pattern with ^,a,b,c,d.So any line containing these characters are displayed.Since
pree
sowmini
does not contain ^ a b c d, they are not displayed

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Saradha Kannan Tue Mar 16, 2010 5:07 pm

@Maithu: Hey can u try my input file s2.txt.. an lemme know wat o/p u get....

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Vineet_More Tue Mar 16, 2010 5:10 pm

Thank you

Vineet_More

Posts : 27
Points : 31
Join date : 2010-02-26

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Tue Mar 16, 2010 5:40 pm

Maithreyi wrote:In the second case, '^abcd' denotes the pattern with ^,a,b,c,d.So any line containing these characters are displayed.Since
pree
sowmini
does not contain ^ a b c d, they are not displayed
No. Here '^' stands for negation.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Maithreyi Tue Mar 16, 2010 5:41 pm

@Sarada : I worked on your file only! What is the pattern you are searching for ?

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Saradha Kannan Tue Mar 16, 2010 5:48 pm

I wanto know wat o/p u get wen u give '[^abcd]' for grep pattern...

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Maithreyi Tue Mar 16, 2010 5:59 pm

Ya Christopher is right.It is negation! But then how is this output justified
grep '[^abcd]' s2.txt
sara
saran
sasi

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Saradha Kannan Tue Mar 16, 2010 6:01 pm

tats wat i ve been askin...
and i get the whole i/p file as o/p..
confused!!!!!

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Tue Mar 16, 2010 6:02 pm

Im getting completely different output.

Code:

$ grep '[^abcd]' s2.txt
sara
pree
saran
sowmini
sasi
this s how it should work.


Last edited by Christopher on Tue Mar 16, 2010 6:06 pm; edited 1 time in total
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Maithreyi Tue Mar 16, 2010 6:04 pm

'[^abcd]' .Here ^ stands for negation.The output shows all lines which contain characters other than abcd.Since all your lines in the file have characters other than abcd, all lines are printed.

Now append baba to your file
say cat >> s2.txt
baba

And then try the command.You will get the output excludign baba!Hope it helps!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Vineet_More Tue Mar 16, 2010 6:05 pm

Yes, i agree with christopher.. but i dnt know why i previously got this as output:
grep '[^abcd]' s2.txt
sara
saran
sasi

Vineet_More

Posts : 27
Points : 31
Join date : 2010-02-26

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Maithreyi Tue Mar 16, 2010 6:06 pm

I agree with Christopher as well! Previously I got a different output.Now it seems to be working correctly!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Tue Mar 16, 2010 6:08 pm

i too got some strange output sometimes Sad
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by akalya Tue Mar 16, 2010 6:10 pm

[335802@oracleclient ~]$ grep '[^abcd]' s2.txt
sara
pree
saran
sowmini
sasi
[335802@oracleclient ~]$ grep [^abcd] s2.txt
sara
pree
saran
sowmini
sasi
[335802@oracleclient ~]$ grep ['^'abcd] s2.txt
sara
pree
saran
sowmini
sasi

wats the difference in the above 3 commands???

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Maithreyi Tue Mar 16, 2010 6:13 pm

As far as I can see, no difference in output!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Christopher Tue Mar 16, 2010 6:19 pm

yes. all d 3 stmts means the same.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Doubt in grep command - Page 2 Empty Re: Doubt in grep command

Post by Sponsored content


Sponsored content


Back to top Go down

Page 2 of 3 Previous  1, 2, 3  Next

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum