Computing.Net > Forums > Unix > grep search in multiple dirs

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

grep search in multiple dirs

Reply to Message Icon

Name: covina
Date: February 22, 2007 at 11:22:28 Pacific
OS: AIX 5.3
CPU/Ram: 512
Product: IBM
Comment:

Need help to grep for a string in each and every files in multiple folders just like the find command works
find ./ -name abc.txt -print

Any help would be appreciated.

Regards



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 22, 2007 at 11:59:28 Pacific
Reply:

Use find with the -exec option:

find . -type f -name "*.txt" -exec grep string {} \; -print

or use find with xargs

find . -type f -name "*.txt" -print|xargs grep string

xargs is more efficient because -exec spawns a new shell each time it executes. Also, in the past -exec has overflowed the buffer if lots of files were found. Most modern *nixes won't do that now.



0

Response Number 2
Name: covina
Date: February 23, 2007 at 08:00:21 Pacific
Reply:

It works great.

Boooyaaa Thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: grep search in multiple dirs

contextual GREP in Unix www.computing.net/answers/unix/contextual-grep-in-unix/6011.html

change string in multiple file www.computing.net/answers/unix/change-string-in-multiple-file/4697.html

hw 2 search fr *.txt in current dir www.computing.net/answers/unix/hw-2-search-fr-txt-in-current-dir/8222.html