>Anyone know how to write a grep -C in Perl ?
Why not just store the previous line, then when you have a match,
print it, the matching line, then set a flag to print the next line as well?
Something along the lines of:
while ($line = <IN>) {
if ($print_next) {
# previous line matched, print this line as following "context"
print $line;
$print_next = 0;
}
if ($line =~ /$pattern/) {
print $last;
print $line;
$print_next = 1; # flag to print the next line
}
$last = $line;
}
That should work unless you want to make sure you never print the
same line twice or if you want more than one line of context.
---Larry
+------------------------------------------------------------------------+
| Larry Coffin, G.P.H. Watertown, MA |
| http://www.PointInfinity.com/lcoffin/ [EMAIL PROTECTED] |
+------------------------------------------------------------------------+
Money is the root of all evil, and man needs roots
-
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]