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!

shell cmd to search for an item and print 3 lines 1

Status
Not open for further replies.

marrow

Technical User
Jul 20, 2001
425
US
I have a large logfile (Solaris 2.6) and am searching for an occurrance of an IP address and then want to print that address plus the next 3 lines. I could simply more it but I'd like to do it in a script. I beleive "sed" might achieve this or is nawk better. Examples appreciated.
 
Hi marrow. Quick and dirty way would be ...

awk '/w.x.y.z/ {print;getline;print;getline;print;getline;print;}' log_file

Just put the correct IP address as the pattern to match.

Greg.
 
Thanks Grega,

That'll do nicely.

Marrow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top