[Novalug] grep usage request

Richard Rognlie rrognlie@gamerz.net
Wed May 7 09:36:29 EDT 2014


On Wed, May 07, 2014 at 09:31:02AM -0400, greg pryzby wrote:
> man grep
> (there are examples)
> 
> grep "1Adam P" * (search local directory)
> find /home/chowe -type f | xargs grep "1Adam P" (will search your home dir
> and subdirs)

A word of warning on the find mechanism.  If any of your filenames have
spaces in them, it will confuse the xargs... Unless you do the following

find /home/chowe -type f -print0 | xargs -0 grep "1Adam P" /dev/null

Why do I have the /dev/null at the end, you ask?

Because, xargs takes standard input and bunches it up.
There is a slight chance that your input will only have 1 file or
that the final execution of grep would have only a single file...  
e.g. your input has 257 filenames, and xargs does a batch of 256 then a
batch of 1.

When grep runs, if there is only a single filename, it will not display
the name of the file that matched.  Adding /dev/null forces the grep
to always have at least 2 filenames, therefore always display the matching
files.  Sure, there's probably a cmdline switch in grep for that, but 
I can never remember it.

> 
> 
> 
> 
> On Wed, May 7, 2014 at 4:52 AM, <cmhowe@patriot.net> wrote:
> 
> > List,
> >
> > Will a few of you give me an exanple or two or three (no more) of using
> > grep. Look for 1Adam P. That will not be enough, but refining the question
> > won't happen until 9:30 am at the earliest
> >
> > Charlie
> >
> >
> > _______________________________________________
> > Novalug mailing list
> > Novalug@calypso.tux.org
> > http://calypso.tux.org/mailman/listinfo/novalug
> >
> 
> 
> 
> -- 
> greg pryzby                              greg at pryzby dot org
> http://www.linkedin.com/in/gpryzby
> 
> TWTR: gpryzby
> WEB:  http://www.MakeRoomForArt.com/
> BLOG: http://lonetrikerphotography.tumblr.com/ (photos)

> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/mailman/listinfo/novalug


-- 
 /  \__  | Richard Rognlie / Scality CSE / Gamerz.NET Lackey
 \__/  \ | http://www.gamerz.net/~rrognlie    <rrognlie at gamerz.net>
 /  \__/ | Creator of pbmserv@gamerz.net
 \__/    |                Helping reduce world productivity since 1994



More information about the Novalug mailing list