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!

Grep on ; and also print the line and 3 above it 2

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I hope I have not been too much today, my script keeps changing.

I have a file which has a print out like such below:

DATE TIME TRTYPE PRCA USER IO
2002-05-16 080258 C AMTP-0

ALLIP;

The file is named cmd_out. I need to grep on the file for ; (semicolon) then send that line and the three above it to another file > beaster1

Any suggestions?

Thanks,
Beaster
 
You could use the following awk script.
Code:
/;/{print a1;print a2;print a3;print}
   {a1=a2;a2=a3;a3=$0}
Hope this helps. CaKiwi
 
CaKiwi,
Your responses have always been the ones that have solved my problems, but today I feel like an idiot for asking, but what would be the complete awk format for this?

Again, Thanks for your help!

Beaster
 
You could put the script into a file, a.awk say, and enter

awk -f a.awk your-file > out-file

Hope this helps.
CaKiwi
 
That was it! Thanks CaKiwi, as always you have been a great help! Works perfect!

Beaster
 
Then give him a star !
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top