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

Grep Question

Status
Not open for further replies.

iceman4000000

Programmer
Jun 7, 2001
30
GB
Hi all,

Was wondering if anyone knew how to grep a line, and also pull out the line that immediately follows it...

For example - we have a program that sends tcp strings to a database and then gets a string back which all goes into a log file. I can grep the send string fine - but is there an easy way to simply pull out that line and the following line (which should be the answer from the database)??

Any help would be much appreciated.

ICE
 
If you have GNU grep, take a look at the -A option.
The awk way:
awk '/SearchPattern/{print;getline;print}' /path/to/inputfile
The sed way:
sed -n '/SearchPattern/{;p;n;p;}' /path/to/inputfile

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
grep -A1 pattern file

man grep gave the solution and should earn the asterix.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top