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

Search for Pattern, Print the line and print the next 10 or x lines below it 1

Status
Not open for further replies.

madasafish

Technical User
Jul 18, 2006
78
TH
I have seen this snippet of code somewhere and have trawled back 10 pages looking for it.
Apologies if this is a repeat question on the forum.

Please note there will be multiple occurrences of "Pattern".

Thanks in advance
Madasafish

 
Hi

Code:
awk '[fuchsia]/pattern/[/fuchsia][teal]{[/teal]c[teal]=[/teal][purple]11[/purple][teal]}[/teal]c[teal]&&[/teal]c[teal]--[/teal]' /input/file
Note that the c value includes the matching line itself.

Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

But personally I would check first whether the available [tt]grep[/tt] implementation supports [tt]-A[/tt] ( [tt]--after-context[/tt] ) option :
Code:
grep -A 10 'pattern' /input/file

Feherke.
[link feherke.github.com/][/url]
 
I have seen this snippet of code somewhere
Here ? thread822-1693595

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top