Solved

Searching for a word within a list of files

Posted on 2001-06-05
4
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 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