Sep 18, 2012 #1 w5000 Technical User Joined Nov 24, 2010 Messages 223 Location PL gnu grep: grep -A n -B m ... in awk, sed, perl... to be as shortest as possible anyone could please provide? thank you.
gnu grep: grep -A n -B m ... in awk, sed, perl... to be as shortest as possible anyone could please provide? thank you.
Sep 18, 2012 #2 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR Provide WHAT ? Hope This Helps, PH. FAQ219-2884 FAQ181-2886 Upvote 0 Downvote
Sep 18, 2012 3 #3 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR 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 Upvote 0 Downvote
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
Sep 18, 2012 Thread starter #4 w5000 Technical User Joined Nov 24, 2010 Messages 223 Location PL right, I don't have GNU grep on a system. thank you. Upvote 0 Downvote
Sep 18, 2012 #5 SamBones Programmer Joined Aug 8, 2002 Messages 3,186 Location US Wow! Another star for PHV for pulling the question out of an obscure and ambiguous post, AND providing a great response! Kudos! Upvote 0 Downvote
Wow! Another star for PHV for pulling the question out of an obscure and ambiguous post, AND providing a great response! Kudos!