in reply to Re^2: grep -A10 oneliner?
in thread grep -A10 oneliner?

The first is trivial: set the number to be the total number of context lines you want, including the matched pattern line.

The second is a little trickier:

perl -ne 'print if $.=/pattern/?1:2..10'
In this case, it will print 10 lines after the match.

Update: so tricky, in fact, that you can't do it with the range operator. So there's no point in using $.. So you just do

perl -ne 'print if$c=/pattern/?11:$c&&$c-1'
or any of the other solutions here. Sigh.
One that doesn't require you to add one to the number you put in:
perl -ne 'print if(/pattern/?$c=10:$c--)>0'

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^4: ...in 43 chars
by gam3 (Curate) on Apr 14, 2005 at 21:54 UTC
    And one charater less
    perl -ne 'print if$c=/pattern/?11:$c-!!$c'
    -- gam3
    A picture is worth a thousand words, but takes 200K.