Grep Command Help

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
jagadam
Premium Member
Premium Member
Posts: 107
Joined: Wed Jul 01, 2009 4:55 pm
Location: Phili

Grep Command Help

Post 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.
NJ
PaulVL
Premium Member
Premium Member
Posts: 1315
Joined: Fri Dec 17, 2010 4:36 pm

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post 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
pandeeswaran
Post Reply