grep, etc

Fairlight fairlite at fairlite.com
Wed Aug 18 14:48:19 PDT 2004


On Wed, Aug 18, 2004 at 04:12:28PM -0400, J. P. Radley, the prominent pundit,
witicized:
> 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.

Bob:  Store the lines in an array, and then using the following.  This will
nuke the last line.  Use shift if you want to instead nuke the first line.  

if (scalar(@result_lines) % 2) {
     pop(@result_lines);
}
print(@result_lines);

> How is that any handier than the -C (or the -A and -B) options of GNU
> grep?

JPR:  "Perl regexps."

mark->
-- 
Bring the web-enabling power of OneGate to -your- filePro applications today!

Try the live filePro-based, OneGate-enabled demo at the following URL:
               http://www2.onnik.com/~fairlite/flfssindex.html


More information about the Filepro-list mailing list