[SunHELP] grep
Phil Stracchino
alaric at caerllewys.net
Thu Jul 31 19:20:23 CDT 2003
Bret Adams <bret at fabrikant.com> wrote:
> 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.
Well, if there's only one instance somewhere in the file, you could grep
-C 2 foobar <file> | head -3 .....
If there's multiple instances, this won't work, of course. I tend to
use Perl, in which it's trivial, for things like this.
--
.********* Fight Back! It may not be just YOUR life at risk. *********.
: phil stracchino : unix ronin : renaissance man : mystic zen biker geek :
: alaric at caerllewys.net : alaric-ruthven at earthlink.net : phil at latt.net :
: 2000 CBR929RR, 1991 VFR750F3 (foully murdered), 1986 VF500F (sold) :
: Linux Now! ...Because friends don't let friends use Microsoft. :
More information about the SunHELP
mailing list