[SunHELP] grep

Sheldon T. Hall shel at cmhcsys.com
Thu Jul 31 18:21:34 CDT 2003


 Sandwich Maker said ...
> "From: Bret Adams <bret at fabrikant.com>
> "
> "I was trying to find a way to grep a pattern in a file and then
> print out
> "that line and the two lines preceding the match.
> "I already manned the grep, egrep and fgrep man pages and nothing
> was listed
> "that fit the bill.  Maybe there is a more robust version
> "of grep out there.  Any pointers would be appreciated.  Thanks
> in advance.
>
> i can think of a dirty hack that would grep -n for the line number,
> then tail +number <file> | tail -3 ...

What you really want is sed ... see
http://216.239.37.104/search?q=cache:D-ewLQAh5wkJ:www.eyetap.org/ece385/orei
lly/unix/upt/ch34_17.htm+cgrep.sed

for Google's cached copy of the cgrep.sed script from Unix Power Tools.

-Shel



More information about the SunHELP mailing list