Si Veteran Posted March 25, 2004 Veteran Share Posted March 25, 2004 I need to search for a specific phrase in a bunch of files that are all in subfolders by month. I know I can do a cat * | grep <phrase> in each folder but how would I run this from the top level and get it to look in all the folders? something to do with ls -R ? Link to comment Share on other sites More sharing options...
RoboStac Posted March 25, 2004 Share Posted March 25, 2004 for f in `ls -R`; do cat "$f" | grep <phrase>; done You'll have to ignore all the directory warnings, or add more filtering. Link to comment Share on other sites More sharing options...
Si Veteran Posted March 25, 2004 Author Veteran Share Posted March 25, 2004 for f in `ls -R`; do cat "$f" | grep <phrase>; done You'll have to ignore all the directory warnings, or add more filtering. That appears to get stuck :/ Link to comment Share on other sites More sharing options...
kjordan2001 Posted March 25, 2004 Share Posted March 25, 2004 cat `ls -R` | grep <phrase> Link to comment Share on other sites More sharing options...
Si Veteran Posted March 25, 2004 Author Veteran Share Posted March 25, 2004 cat: ls -R: No such file or directory :( Link to comment Share on other sites More sharing options...
trpn Posted March 25, 2004 Share Posted March 25, 2004 wouldn't it just be grep -r <phrase> top-level-dir Link to comment Share on other sites More sharing options...
MrStaticVoid Posted March 25, 2004 Share Posted March 25, 2004 cat: ls -R: No such file or directory :( Those are backticks around the ls -R. The backtick is above Tab. Link to comment Share on other sites More sharing options...
kjordan2001 Posted March 25, 2004 Share Posted March 25, 2004 wouldn't it just be grep -r <phrase> top-level-dir Only problem with that is I think that might look inside text files too and find the phrase in that as well. Link to comment Share on other sites More sharing options...
Si Veteran Posted March 26, 2004 Author Veteran Share Posted March 26, 2004 Those are backticks around the ls -R. The backtick is above Tab. :pinch: Thanks! (Y) Link to comment Share on other sites More sharing options...
Tek Posted March 26, 2004 Share Posted March 26, 2004 find | grep <phrase> The find command lists every file in every directory underneath the current dir. Link to comment Share on other sites More sharing options...
JelloSnake Posted March 28, 2004 Share Posted March 28, 2004 Yeah, Im going to have to agree with trpn, this is how you can search from the top directory down. grep -r whatever * I use that every day when I am looking for spammers or whatever in log files. Link to comment Share on other sites More sharing options...
Recommended Posts