I was wondering if anyone knows of a command that can grep a file for a
certain keyword ( that would be grep, right ? ) , but instead of just
displaying the line with the keyword, display a number of lines before
and after that specific line.
What I want to do is grep a file for e.g. "error" and then have it
display to me the whole set of lines concerning the error.
IF for example you get a disk error , only one line has the error
keyword, but the interesting data is in the lines following ...
Thanks for any help or hints in advance,
Bart
Sent via Deja.com http://www.deja.com/
Before you buy.
Bart, I would suggest you look into AWK, it is ideal for pattern matching
and performing
conditional operations on files .... failling that you could grep -n to get
the line number and
then head/tail different parts of the file working with that number to get
the relevant lines
although that could turn a little messy!
rgds
steve
but I think I am going to jump to Perl if scripting gets involved. A
standard tool would be nicer of course , since I would get this on any
machine I lay me hands on ... might be a suggestion for Sun to include
on their freeware CD ?!
Cheers ,
Bart
In article <962802401.23281.0...@news.demon.co.uk>,
GNU grep can do this, with its -A, -B, and -<number> options.
--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
> Hello,
>
> I was wondering if anyone knows of a command that can grep a file for a
> certain keyword ( that would be grep, right ? ) , but instead of just
> displaying the line with the keyword, display a number of lines before
> and after that specific line.
I think GNU's grep does what you're after.
--
Rich Teer
NT tries to do almost everything UNIX does, but fails - miserably.
The use of Windoze cripples the mind; its use should, therefore, be
regarded as a criminal offence. (With apologies to Edsger W. Dijkstra)
Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
> I was wondering if anyone knows of a command that can grep a file for a
> certain keyword ( that would be grep, right ? ) , but instead of just
> displaying the line with the keyword, display a number of lines before
> and after that specific line.
>
> What I want to do is grep a file for e.g. "error" and then have it
> display to me the whole set of lines concerning the error.
> IF for example you get a disk error , only one line has the error
> keyword, but the interesting data is in the lines following ...
Sounds like you should check out GNU grep, downloadable from
ftp://ftp.gnu.org/pub/gnu/grep/
It supports the -C (context), -A (after) and -B (before) options, all of
which take a integer to specify how many lines to show. So if you want
to see all occurances of the regexp "blah" in a file with their
following 3 lines you would use the command
grep -A3 "blah" file
Philip Guenther
----------------------------------------------------------------------
guen...@gac.edu UNIX Systems and Network Administrator
Gustavus Adolphus College St. Peter, MN 56082-1498
Source code never lies: it just misleads (Programming by Purloined Letter?)
> Date: Wed, 5 Jul 2000 14:55:55 +0200
> From: Steve Middleton <st...@dataload.co.uk>
> Newsgroups: comp.sys.sun.admin
> Subject: Re: Is there something like a "wide" grep ?
>
>
> <bartw...@my-deja.com> wrote in message
> news:8jutbr$rnm$1...@nnrp1.deja.com...
> > Hello,
> >
> > I was wondering if anyone knows of a command that can grep a file for a
> > certain keyword ( that would be grep, right ? ) , but instead of just
> > displaying the line with the keyword, display a number of lines before
> > and after that specific line.
> >
> > What I want to do is grep a file for e.g. "error" and then have it
> > display to me the whole set of lines concerning the error.
> > IF for example you get a disk error , only one line has the error
> > keyword, but the interesting data is in the lines following ...
GNU Grep works. The -A and -B options. The grep included with Solaris
is a bit weak.
-Mitch Richling
=== Mitch J. Richling ====== http://www2.airmail.net/richmit/index.html ==
| Texas Instruments Inc. | Office: K1-14444 | Home: 972-301-3148 |
| 12500 TI Blvd. MS#8717 | Phone: 214-480-4435 | Cell: 214-497-1105 |
| Dallas ASP Design Computing | Pager: 214-961-0935 | Wife: 214-497-1103 |
| Dallas, TX 75243 | Fax: 214-408-2700 | |
==== ric...@dal.asp.ti.com ===== ric...@member.ams.org =================
Quote: "1+1=2" -o)
-- A.N. Whitehead & B. Russell, /\\
Principia Mathematica, Vol. II, p. 83. _\_v