Alex_Tong
asked on
Searching for a word within a list of files
Given a list of files, how can I find a specific word or phrase?
i.e. something like...
find . -name myfile |grep -i evil_subroutine *
I want to look for all occurances of myfile and search all occurances for "evil_subroutine"
-Alex
i.e. something like...
find . -name myfile |grep -i evil_subroutine *
I want to look for all occurances of myfile and search all occurances for "evil_subroutine"
-Alex
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That was wierd... I said "Sumbit" and only part got posted... Let's try again...
You can do it with find. If you want to find all the strings in all of the files, do:
find . -name myfile -exec grep -i evil_subroutine {} \;
Or if you want to know only what files contain the string do:
find . -name myfile -exec grep -il evil_subroutine {} \;
The standard operators for find apply so to look in C source files you might do:
find . -name "*.c" -exec grep -i evil_subroutine {} \;
Or if there isn't a pattern to the file names you can avoid grepping directories with:
find . -type f -exec grep -i evil_subroutine {} \;
See "man find" and "man grep" for more information.
You can do it with find. If you want to find all the strings in all of the files, do:
find . -name myfile -exec grep -i evil_subroutine {} \;
Or if you want to know only what files contain the string do:
find . -name myfile -exec grep -il evil_subroutine {} \;
The standard operators for find apply so to look in C source files you might do:
find . -name "*.c" -exec grep -i evil_subroutine {} \;
Or if there isn't a pattern to the file names you can avoid grepping directories with:
find . -type f -exec grep -i evil_subroutine {} \;
See "man find" and "man grep" for more information.
ASKER
Fantastic answer.
Thanks jlevie
Thanks jlevie
for i in `find . -name myfile`
do
echo "Processing" $i
grep "evil_subroutine" $i
done