grep, etc

Jean-Pierre A. Radley appl at jpr.com
Wed Aug 18 16:49:31 PDT 2004


Bob Stockler propounded (on Wed, Aug 18, 2004 at 07:24:59PM -0400):
| On Wed, Aug 18, 2004 at 04:12:28PM -0400, Jean-Pierre A. Radley wrote:
| | Bob Stockler propounded (on Wed, Aug 18, 2004 at 03:31:43PM -0400):
| | | I have a little perl program (cgrep) that prints N (default 3)
| | | lines on each side of a line matching a pattern.  If you want
| | | an uneven number of lines that would be fine (though slower that
| | | the AWK program), but if you wanted an even number of lines its
| | | output would have to be piped through grep -v to remove either
| | | the first or last line.
| | 
| | How is that any handier than the -C (or the -A and -B) options of GNU
| | grep?
| 
| I don't know how it differs because I've neve used GNU grep.
| 
| I also don't know where I got it or how long ago it was because
| I just edited it to change its first line from:
| 
|      #!/usr/local/bin/perl
| to:
|      #!/usr/bin/perl
| 
| so it must have been some while ago,
| 

>From GNU grep man page:

	-A NUM, --after-context=NUM
	      Print NUM lines of trailing context after matching lines.
	      Places a line containing -- between contiguous groups of
	      matches.

	-B NUM, --before-context=NUM
	      Print NUM lines of leading context before matching lines.
	      Places a line containing -- between contiguous groups of
	      matches.

	-C NUM, --context=NUM
	      Print NUM lines of output context.  Places a line containing --
              between contiguous groups of matches.

(BTW, you can get a whole lot of GNU binaries for your machine from
ftp://ftp.sco.com/pub/openserver5/opensrc/gnutools-5.0.7Kj.)

-- 
JP


More information about the Filepro-list mailing list