Printing lines after a match is found

Friday, December 28, 2012 1 Comments

The below command prints 4 lines after a match is found.
awk '/^Total Collection =/{c=4;next}c-->0' File
You can change the number of lines to be printed by changing the value of c in the command given.Please find the explanation below:
/^Total Collection =/{c=4;next}
The above statement says  whenever a line starts with "Total Collection =" then initialize c to 4
After that print the line if c is greater than 0 and for each and every line c-- is performed.

1 comment: