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

Mutiline Grep Question

Status
Not open for further replies.

ckattola

Technical User
Aug 27, 2002
1
US
I have a file with about 3 Million lines and I am tring to extract certain lines from the file. I can grep the line that I want but I also want to grep the four lines that follow. If I use the -e option to grep the other four lines I get nearly the whole file since each line format is very similar. The trick being that I want to grep a certain number first then the next four lines then goto the next number.

So for example I want to grep 12345 then the next four lines then 12345 again then the next four lines skiping everything between the last line in the set of four and the next 12345 match. Is this possible with a grep statement?

Hoping for help,
ckattola
 
You could use awk

awk '/12345/{print;for(i=0;i<4;i++){getline;print}}' file CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top