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!

Extract subsequent / previous line from a grep'd file

Status
Not open for further replies.

AntP

Programmer
Apr 12, 2002
6
US
I was wondering if there's a simple method from the command line of doing this.

If I have, for example a file (test.txt) containing 3 lines:
a
b
c

I wish to search for the second line, but return whatever is on the line after what I have searched on.

I can do the grep b test.txt...naturally this will return the 2nd line to the prompt, I wish to however get the third line instead of the one which was grep'd for.
Defo possible in Perl, however I'm wondering if there's any simpler way of doing this from the command line, or even something in awk? %-)

Thanks a bunch for your thoughts/comments.
 
Cool. Many thanks.
That text file is v. handy.

sed - awk - awk - sed.

I got the three letters, just the wrong one's. (-:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top