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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print the field number containing word pls ... 1

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

Probably this is simple, but I couldn't figure it out..

I would like to print the field number containing particular "word" for each line.

How do I do that in awk or sed ?

Thx guys,
 
One way ...

Code:
awk ' {

for(fieldno=1; fieldno<=NF; fieldno++)
   if($fieldno == "word")
      printf("%d\n", fieldno)

} ' data.file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top