Date: Sat, 13 Jul 1996 20:36:08 -0600 From: Sean Kelly <kelly@fsl.noaa.gov> To: kline@tera.com Cc: tcg@ime.net, questions@freebsd.org Subject: Re: Recursive grep. Message-ID: <199607140235.CAA15751@gatekeeper.fsl.noaa.gov> In-Reply-To: <199607140128.SAA09139@athena.tera.com> (message from Gary Kline on Sat, 13 Jul 1996 18:28:33 -0700 (PDT))
next in thread | previous in thread | raw e-mail | index | archive | help
>>>>> "Gary" == Gary Kline <kline@tera.com> writes:
Gary> If some of you unix command wizards will
Gary> indulge me: why is ``/dev/null'' at the end of the command??
I'm no wizard, but I'll indulge:
Grep with multiple filenames on its command line will print each line
that matches the pattern from each file *prepended with the file name*.
If you invoke grep with just one file name, grep prints the matching
lines *without any filename*. Makes sense, right? After all, if you
type
grep <pattern> *
you want to see which files contained the <pattern>. If you type
grep <pattern> foobar
you already know what file you're working with.
Well, there's an off-chance that xargs will execute grep with just one
filename. Xargs is working along reading a bunch of files and
building up huge command lines and executing grep. But the last
command line was large enough so there's just one file left ... so
xargs executes
grep <pattern> <some-file>
And if the <pattern> matches a line in <some-file>, you'll see the
matching lines but won't have any idea in which file they matched!
But you want to see which file it was that had the pattern---so throw
a /dev/null on there and grep will always have at least two filenames
to play with---thereby forcing it to prepend the name of the file in
front of each matching line.
--
Sean Kelly
NOAA Forecast Systems Laboratory kelly@fsl.noaa.gov
Boulder Colorado USA http://www-sdd.fsl.noaa.gov/~kelly/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607140235.CAA15751>
