Solved

Searching for a word within a list of files

Posted on 2001-06-05
4
339 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:Alex_Tong
  • 2
4 Comments
 
LVL 6

Expert Comment

by:bira
ID: 6157469
I would suggest you to use a script, like this:

  for i in `find . -name myfile`
  do
  echo "Processing" $i
  grep "evil_subroutine" $i
  done
0
 
LVL 40

Accepted Solution

by:
jlevie earned 30 total points
ID: 6157494
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 {} \;
0
 
LVL 40

Expert Comment

by:jlevie
ID: 6157516
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.
0
 

Author Comment

by:Alex_Tong
ID: 6157702
Fantastic answer.
Thanks jlevie
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now