Solved

Searching for a word within a list of files

Posted on 2001-06-05
4
333 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
CPU monthly average? 12 92
auto mounter on solaris 1 40
How to Change Interface on Cisco IOU 11 74
How to Insert a File Using Text Editor 9 55
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…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
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.:

760 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

20 Experts available now in Live!

Get 1:1 Help Now