On Wed, 1 May 2002, David Cantrell wrote:
> On Tue, Apr 30, 2002 at 03:40:20PM -0700, Palit, Nilanjan wrote:
> > This is really a unix question, but I thought I'll ask it here, in case
> > there is a perl tool to do the same:
> >
> > Is there an (easy) way of doing a grep with a 'context', i.e. grep will
> > provide the previous N & next M lines for every line that matches the
> > pattern (where N & M are arguments to the command)?
>
> No. You could lash something up by making grep spew out line numbers and
> then feeding them to awk.
Oh, I don't know about that -- some machines have a version of Grep that
can do context. To wit:
cdevers@plough:~$ grep --help | grep -A1 ' context'
-B, --before-context=NUM print NUM lines of leading context
-A, --after-context=NUM print NUM lines of trailing context
-C, --context[=NUM] print NUM (default 2) lines of output context
unless overridden by -A or -B
cdevers@plough:~$ which grep
/bin/grep
cdevers@plough:~$ uname -a
Linux plough 2.2.18pre21 #1 Wed Nov 22 16:18:08 EST 2000 sparc unknown
cdevers@plough:~$
:) :) :)
--
Chris Devers [EMAIL PROTECTED]
Apache / mod_perl / http://homepage.mac.com/chdevers/resume/
"More war soon. You know how it is." -- mnftiu.cc