Computing.Net > Forums > Unix > using find; can I use grep as well?

using find; can I use grep as well?

Reply to Message Icon

Original Message
Name: Siow Wei
Date: January 15, 2003 at 05:08:38 Pacific
Subject: using find; can I use grep as well?
OS: Win 2000
CPU/Ram: 256
Comment:

Dear all,

Facing another problem. One of the users had kindly taught me the usage of -perm and it does help me alot.. well I have another problem here.

Locate all ordinary files within your Intra-group directory that have the pattern of SPA in their contents and view their contents one by one after confirmation.

As I know, it could begin like this(assume that I am in my Intra-group directory):
$find . -type f ( to find ordinary files)

AND
...-ok cat {} \; (to confirm to view the contents)

BUT to to find the files that have pattern of SPA in the contents.. am scratching head to think of the solution. Please help.

Student,
Siow Wei


Report Offensive Message For Removal


Response Number 1
Name: James Boothe
Date: January 15, 2003 at 07:36:32 Pacific
Subject: using find; can I use grep as well?
Reply: (edit)

find . -type f -name "*SPA*"


Report Offensive Follow Up For Removal

Response Number 2
Name: shahid hussain
Date: January 24, 2003 at 05:44:52 Pacific
Subject: using find; can I use grep as well?
Reply: (edit)

if you're searching for the contents in the file try this:

find . -type f | xargs grep "string_to_search_for"

the dot above is where you want to begin the search from...for example if you want to find all files that have the word "rules" beginning from /export, you'll type

find /export -type f | xargs grep "rules"


Report Offensive Follow Up For Removal

Response Number 3
Name: WilliamRobertson
Date: February 14, 2003 at 05:00:33 Pacific
Subject: using find; can I use grep as well?
Reply: (edit)

Also you might try grep -l which lists the file name only, rather than listing all the matching lines.

An alternative to xargs is to nest commands e.g:

grep -l 'SPA' $(find path -type f)

One advantage of the ksh $() syntax (as opposed to sh's ``) is you can nest that again e.g:

vi $(grep -l 'SPA' $(find path -type f) )


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: using find; can I use grep as well?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge