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!

different emulations of... 3

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL

gnu grep:

grep -A n -B m ...

in awk, sed, perl... to be as shortest as possible anyone could please provide?

thank you.
 
Provide WHAT ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Oh, I think I understand:
You don't have a gnu grep version and want to emulate its -A and -B options, right ?
A starting point:
Code:
awk -vA=[i]n[/i] -vB=[i]m[/i] -vp=[i]'pattern'[/i] '
{x[FNR%(B+1)]=$0}
$0~p{n=FNR;for(i=B;i>=0;--i)if(n-i>0)print x[(n-i)%(B+1)]
     for(i=0;i<A;++i){getline;print}
}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

right, I don't have GNU grep on a system.

thank you.
 
Wow! Another star for PHV for pulling the question out of an obscure and ambiguous post, AND providing a great response!

Kudos!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top