[Novalug] bash commands
Nino Pereira
pereira at speakeasy.net
Fri Jan 18 15:26:51 EST 2008
Thank you all: I now have more than enough choices to play with.
FYI, what does the best (for now: my needs are still simple) is:
grep 'string' *.f
since there are less than 100 files in a single directory
that I want to go through.
The list came through again!
Nino
Richard Rognlie wrote:
> On Fri, Jan 18, 2008 at 03:02:43PM -0500, Joel Fouse wrote:
>> Some grep options I use on a regular basis:
>>
>> -i ... search case-insensitively
>> -r ... search recursively (in the example above, you wouldn't even
>> need the -r if all the files are in the same folder)
>
> Unless the "pattern" you are trying to match (say *.f) results in a very
> large number of matches, and the bash command line balks...
>
> I don't know what that number is, but it's on the order of 1024...
>
>> -l ... show only the filenames that contain matches rather than
>> displaying each matching line
>> -c ... show all filenames scanned with the number of matching lines
>> contained in each (including zero)
>>
>> As Jeff pointed out, the file parameter isn't limited to a single name;
>> rather, you can use all manner of what they call shell globbing, because
>> the bash shell converts the globs to concrete filenames before passing
>> them on to grep as distinct parameters:
>>
>> grep 'stringToFind' *.[ch] // search for term in all files ending in
>> ".c" or ".h"
>>
>> You can also use multiple filename arguments:
>>
>> grep -r 'stringToFind' ./subDir1/*.[ch] ./subDir3/*.txt ./subDir5
>>
>> Grep is your friend. It's very rare that I need to use some other
>> utility in conjunction with it (cat, find, etc.).
>
> I guess I'm old school... grep -r is "new". and not all unixes support it.
> therefore
>
> find dir | xargs grep pattern
>
> is a habit I use that I *know* will always work.
>
>
More information about the Novalug
mailing list