The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to remove all matches in a string with sed lumix Shell Programming and Scripting 0 12-14-2007 08:09 PM
creating folder when the string matches maximas Shell Programming and Scripting 2 10-04-2007 08:24 AM
to create foder when the string matches maximas Shell Programming and Scripting 1 09-28-2007 06:23 AM
Printing the following line that matches an string jgarcia Shell Programming and Scripting 7 05-10-2007 02:31 AM
String in text matches folder name shackman66 Shell Programming and Scripting 2 05-05-2004 06:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2007
btrotter btrotter is offline
Registered User
  
 

Join Date: Mar 2007
Location: North Carolina
Posts: 2
Looking for a string in files and reporting matches

Can someone please help me figure out what the command syntax I need to use is?

Here is what I am wanting to do.

I have hundreds of thousands of files I need to look for a specific search string in.
These files are spread across multiple subdirectories from one main directory.
I would like to find a way to search through all these files, and everytime it sees a file with this specific search string in it, make a note of it in a log file.

So, for instance, I have the directory /files/accounting/
Under /files/accounting, I have LOTS of Microsoft Excel files that I want to search for the specific string "\\cttrut04\dept\" and then everytime it finds a file by that name, dump it to a log file.

I thought about something like:

find /files/accounting/ -name "*xls" | more | grep -i "\\clttrut04\dept" > \log\filelog.txt

This doesnt work. I am not sure how to do a find and then feed each file name it finds to more to search it and then grep it for the search string.

Can anyone help with this?

Thank you,
Brian
  #2 (permalink)  
Old 03-28-2007
gopidesaboyina gopidesaboyina is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 29
find /files/accounting/ -name *.xls -exec grep -i '\\\\clttrut04\\dept' /dev/null {} \;
  #3 (permalink)  
Old 03-28-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,802
Maybe change grep -i to grep -i -l to report the filename. This is what I take "make a note of it" to mean.
  #4 (permalink)  
Old 03-28-2007
btrotter btrotter is offline
Registered User
  
 

Join Date: Mar 2007
Location: North Carolina
Posts: 2
Quote:
Originally Posted by gopidesaboyina
find /files/accounting/ -name *.xls -exec grep -i '\\\\clttrut04\\dept' /dev/null {} \;
Where does the output of this go?

Also, why do you have four \\\\'s and two \\'s, when the search string is only \\ and \?


Thanks for your help!!!
  #5 (permalink)  
Old 03-29-2007
gopidesaboyina gopidesaboyina is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 29
output shows on screen. if you want you can redirect them to some file. those extra slashes are for escape, other wise it wouldn't find that string as / has special meaning in unix.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0