Page 1 of 1

Grep Command Help

Posted: Mon Jan 16, 2012 11:48 am
by jagadam
Hi,

I need help in grabbing the value after comma from a comma separated file in linux.

Values in a file :

ABC,0
DEF,1
GHI,2
FJK,3

I need to grep value 0 if i pass ABC as a parameter to command.

i tried with grep 'ABC' filename | awk '{print $1}' but unsuccessful.

Could any one please help me.

Thanks in Advance.

Posted: Mon Jan 16, 2012 12:03 pm
by PaulVL
You're also not testing if the file returned nothing for the GREP command, but you're still parsing the stdout of grep.

Posted: Mon Jan 16, 2012 12:36 pm
by chulett
You were 'unsuccessful' how? A full explanation of what you tried and what happened when you tried it can go a long way towards getting a resolution out sooner rather than later.

Posted: Mon Jan 16, 2012 1:31 pm
by pandeesh
yes it should be unsuccessful since there's no FS specified.
try:

Code: Select all

grep "ABC" filename|nawk -F, '{print $2}'

Code: Select all

pandeeswaran@ubuntu:~$ echo abc,0|grep abc|nawk -F, '{print $2}'
0