Doubt in grep command
+8
akalya
hansi
Nazneennazim
SakeenaHarris
anand
Christopher
Maithreyi
lalitha
12 posters
Page 2 of 3 • 1, 2, 3
Re: Doubt in grep command
simply use,
600 th POST IN UNIX
- Code:
grep j <filename>
600 th POST IN UNIX
Last edited by Christopher on Mon Mar 15, 2010 5:09 pm; edited 1 time in total
Re: Doubt in grep command
Well ou can use jj* also
Vineet_More- Posts : 27
Points : 31
Join date : 2010-02-26
Re: Doubt in grep command
$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?
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
Re: Doubt in grep command
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
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
Re: Doubt in grep command
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?
everything is working fine... do u have any problem with ur output?
Re: Doubt in grep command
use single quotes outside square bracket. still u may not notice any difference for this example. try some other example.
Re: Doubt in grep command
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?
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
Re: Doubt in grep command
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
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
Re: Doubt in grep command
@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
Re: Doubt in grep command
No. Here '^' stands for negation.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
Re: Doubt in grep command
@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
Re: Doubt in grep command
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
Re: Doubt in grep command
Ya Christopher is right.It is negation! But then how is this output justified
grep '[^abcd]' s2.txt
sara
saran
sasi
grep '[^abcd]' s2.txt
sara
saran
sasi
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: Doubt in grep command
tats wat i ve been askin...
and i get the whole i/p file as o/p..
confused!!!!!
and i get the whole i/p file as o/p..
confused!!!!!
Saradha Kannan- Posts : 25
Points : 25
Join date : 2010-03-04
Re: Doubt in grep command
Im getting completely different output.
- Code:
$ grep '[^abcd]' s2.txt
sara
pree
saran
sowmini
sasi
Last edited by Christopher on Tue Mar 16, 2010 6:06 pm; edited 1 time in total
Re: Doubt in grep command
'[^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!
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
Re: Doubt in grep command
Yes, i agree with christopher.. but i dnt know why i previously got this as output:
grep '[^abcd]' s2.txt
sara
saran
sasi
grep '[^abcd]' s2.txt
sara
saran
sasi
Vineet_More- Posts : 27
Points : 31
Join date : 2010-02-26
Re: Doubt in grep command
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
Re: Doubt in grep command
[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???
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
Re: Doubt in grep command
As far as I can see, no difference in output!
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Page 2 of 3 • 1, 2, 3
Similar topics
» GREP TO EXTRACT NON DIGIT FROM EXPRESSION
» tee command doubt
» awk command doubt
» doubt in sort command!!!
» doubt in sort command
» tee command doubt
» awk command doubt
» doubt in sort command!!!
» doubt in sort command
Permissions in this forum:
You cannot reply to topics in this forum
|
|