Recursive Linux "Find Files Containing"
This makes use of the regrep script I mentioned earlier.
regrep "whatever" | awk -F":" {'print $1'} | uniq
Prints out a list of files containing whatever pattern you put. Kinda equivalent to Windows' "find files containing" search.
No problem.
I probably should combine the bash and perl scripts into a single (Perl?) script, and make "show file names only" a command-line option instead of piping it through awk.
For now, though, this suits me just fine.
Posted by: Joe Grossberg on October 31, 2003 3:58 PM | permalinkSeems like a lot of trouble -- why don't you simply:
grep -lir "some text" *
or,
find /path -name *.txt | grep -lir "some text" *
??
Posted by: Ken on January 29, 2007 3:50 PM | permalinkYes, and in the 3.5 years since I wrote that post, I've learned about the "-l" flag :)
Posted by: Joe Grossberg on January 29, 2007 4:20 PM | permalinkjust what i was looking for...
thanks joe
thanks ken
So to add a little to Ken's comment
find /path -name *.txt | grep -lir "some text" *
That wouldn't exactly work how it is written.
I wanted to search everywhere, but exclude the /dev , so I did
find * | grep -vi dev | xargs grep -li "some text"
find * returns all file names
grep -v dev returns everything that doesn't have dev (the v inverts the search, i makes it case insensitive)
The reason Ken's wouldn't work is the xargs, the paths for grep to search needed to be handed in as args rather than through the pipe, so his with the * would just search everything anyway.
I also took the r off the last grep so it wouldn't go recursive and look at things not specifically returned.
Posted by: Doug on December 20, 2007 5:31 AM | permalinkHere is an alternative (will find files within subdirectories containing the value that you provide):
find . -name *.extension -exec grep -i -H -n 'texttofind' {} \;
Enjoy!
Posted by: Ken on May 14, 2008 11:37 AM | permalinkNo more comments! Either someone has violated Godwin's Law, I'm tired of the discussion or, most likely, the ten-week window has closed. You can, however, contact me through email.