[comp.unix.questions] cgrep

arensb@cvl.umd.edu (Andrew Arensburger) (07/14/88)

	I'm thinking of writing a utility called cgrep, which works just
like grep, but instead of writing out just the line on which the pattern
was found, would write out a couple of lines surrounding the line in
question.
	Has anyone implemented this, or am I going to have to write it?

						/AA/

alan@jane.Jpl.Nasa.Gov (Alan S. Mazer) (07/14/88)

In article <2985@cvl.umd.edu>, arensb@cvl.umd.edu (Andrew Arensburger) writes:
> I'm thinking of writing a utility called cgrep, which works just like grep

You and everyone else.  I've got one in C which is very similar to egrep, but
with one additional display-context option.  You can select how many lines above
and below you want, and it uses egrep alone when it can.  You're welcome to it.
Send mail.  To people who got earlier versions, I've fixed a couple bugs since
then.  If you want a new one, yell.

	-- Alan		..!cit-vax!elroy!alan		* "But seriously, what
			elroy!alan@csvax.caltech.edu	   could go wrong?"

emv@mailrus.cc.umich.edu (Edward Vielmetti) (07/14/88)

In article <2985@cvl.umd.edu> arensb@lemuria.UUCP (Andrew Arensburger) writes:
>
>	I'm thinking of writing a utility called cgrep, which works just
>like grep, but instead of writing out just the line on which the pattern
>was found, would write out a couple of lines surrounding the line in
>question.

when I needed to do this recently, this is what I cooked up on the
spur of the moment.  It works, though it's by no means optimal.

cgrep:
#!/bin/sh
grep -v $1 $2 | diff -c - $2

all depends on whether your diff can handle standard input or now.
mine can (Apollo SR 10 beta).

You might note that there was a long discussion of 'gre', a new
project from at&t research to do grep right, and as I recall the
prevailing view from the "tools, pipes, filters" crowd was
that context doesn't belong in grep.  The "features, features,
features" crowd thought otherwise.
I'd be interested in a cgrep if you wrote one.

--Ed

inc@tc.fluke.COM (Gary Benson) (07/15/88)

arensb@cvl.umd.edu (Andrew Arensburger) writes:

"	I'm thinking of writing a utility called cgrep, which works just
"like grep, but instead of writing out just the line on which the pattern
"was found, would write out a couple of lines surrounding the line in
"question.
"	Has anyone implemented this, or am I going to have to write it?


Write it! There was quite a discussion here recently about just such a
utility, but noone seemed interested enough to go off and do it. Judging
from the interest level, though, apparently I am not the only one who'd make
use of it. Here's my application:

I have a program that inserts typestting codes into a file, flagging
unrecognized text elements for later manual coding. I'd like to not just
grep for the flags, but be able to see a little of the context that caused
the flag. In fact, if you can add an option to DISinclude the pattern and
show only the context requested, it would be even more useful in my case,
since all the flags look the same -- I don't want to see them at all,
actually, just the text entity that caused it.

Good luck - Please email me a beta test version!


-- 
Gary Benson		   -_-_-_-_-_-_-_-_-inc@tc.fluke.com_-_-_-_-_-_-_-_-_-_
Publication Services	   Ensign Benson, Space Cadet, Digital Circus, Sector R
John Fluke Mfg. Co. Inc.   _-_-_-_{uw-beaver, sun,microsoft}!fluke!inc-_-_-_-_-

fuat@cunixc.columbia.edu (Fuat C. Baran) (07/16/88)

In article <7464@elroy.Jpl.Nasa.Gov> alan@jane.Jpl.Nasa.Gov (Alan S. Mazer) writes:
>In article <2985@cvl.umd.edu>, arensb@cvl.umd.edu (Andrew Arensburger) writes:
>> I'm thinking of writing a utility called cgrep, which works just like grep
>
>You and everyone else.  I've got one in C which is very similar to egrep, but
>with one additional display-context option.  You can select how many lines above
>and below you want, and it uses egrep alone when it can.  You're welcome to it.
>	-- Alan		..!cit-vax!elroy!alan		* "But seriously, what
>			elroy!alan@csvax.caltech.edu	   could go wrong?"

On our system we have a cgrep which seems to do what you want.  I took
a look at the sources.  It carries the following notice:

**   Cgrep - a program to extract context from text files.
**	by David J. Iannucci @@ Saint Joseph's University, Philadelphia
**						  iannucci@@sjuvax.UUCP
**
**			Copyright (c) 1986
**
**	You may do anything you like with this program except:
**		1.  Use it to direct commercial advantage.
**		2.  Take credit for any code I have written.

I don't where we got this from (maybe one of the source groups?).


						--Fuat

-- 
ARPANET: fuat@columbia.edu           U.S. MAIL: Columbia University
BITNET:  fuat@cunixc.cc.columbia.edu            Center for Computing Activities
USENET:  ...!rutgers!columbia!cunixc!fuat       712 Watson Labs, 612 W115th St.
PHONE:   (212) 280-5128                         New York, NY 10025

jbush@ficc.UUCP (james bush) (07/18/88)

In article <4435@fluke.COM>, inc@tc.fluke.COM (Gary Benson) writes:
| arensb@cvl.umd.edu (Andrew Arensburger) writes:
| 
| "	I'm thinking of writing a utility called cgrep, which works just
| "like grep, but instead of writing out just the line on which the pattern
| "was found, would write out a couple of lines surrounding the line in
| "question.
| "	Has anyone implemented this, or am I going to have to write it?
| 
| 
| Write it! ...

I have such a utility, although it has some problems:
1. It is written in AWK, and is therefore slow.
2. It may die on some applications.
3. It seems always to print at least one preceeding line. 
However, you are welcome to it if you want. I am not sure of where
it should be posted. 
-- 
James Bush, Ferranti, Houston              The Bible - the "source code" of life
Internal address: jbush  extension 5230, mail stop A/3204, room A/3602
External address: ..!uunet!nuchat!sugar!ficc!jbush