using the CAT command recursively


Recommended Posts

Si

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 post
Share on other sites
RoboStac

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 post
Share on other sites
Si
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 post
Share on other sites
kjordan2001

cat `ls -R` | grep <phrase>

Link to post
Share on other sites
Si

cat: ls -R: No such file or directory

:(

Link to post
Share on other sites
trpn

wouldn't it just be

grep -r <phrase> top-level-dir

Link to post
Share on other sites
MrStaticVoid
cat: ls -R: No such file or directory

:(

Those are backticks around the ls -R. The backtick is above Tab.

Link to post
Share on other sites
kjordan2001
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 post
Share on other sites
Si
Those are backticks around the ls -R. The backtick is above Tab.

:pinch:

Thanks! (Y)

Link to post
Share on other sites
Tek

find | grep <phrase>

The find command lists every file in every directory underneath the current dir.

Link to post
Share on other sites
JelloSnake

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 post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.