Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need the field that follow specific word

Status
Not open for further replies.

toomee

Technical User
Jan 28, 2003
10
0
0
TH
I have data like this,

a,1,b,2,c,3,d,4,e,5
a,11,b,12,c,13,d,14
b,21,c,22,d,23
a,31,b,32,d,33

I need only the fields that follow b and d like,

2|4
12|14
21|23
32|33

Could anyone help me?
Thank you
 
Something like this ?
awk -F',' '{
b="";d=""
for(i=1;i<NF;++i){
if($i=="b")b=$(i+1)
if($i=="d")d=$(i+1)
};printf "%s|%s\n",b,d
}' /path/to/inputfile

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top