Computing.Net > Forums > Unix > search for word/s in a file

search for word/s in a file

Reply to Message Icon

Original Message
Name: vijaynag
Date: May 28, 2008 at 06:08:58 Pacific
Subject: search for word/s in a file
OS: UNIX
CPU/Ram: intel xeon
Model/Manufacturer: intel
Comment:

hi,

i need a shell script to find the position of one or more words in one line of a file and then get a number/s which is/are located in the same position/s in the next line. I need to do this for many lines till the end of the file. then all these searched number/s along with the word/s should be sent to another file. please help me with this


Report Offensive Message For Removal


Response Number 1
Name: ghostdog
Date: May 30, 2008 at 22:13:13 Pacific
Reply: (edit)


awk '{
if ( match($0,"word") ) {
getline
print $3
next
}
}
' file


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: search for word/s in a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge