The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 find a file named vijay in a directory using find command amirthraj_12 UNIX for Dummies Questions & Answers 6 10-25-2008 12:37 PM
How to read an Xml record contained in a file--urgent aixjadoo UNIX for Advanced & Expert Users 4 06-19-2008 06:38 AM
find and replace string in a directory files koti_rama Shell Programming and Scripting 2 05-30-2008 03:48 AM
Unix find command to print directory and search string princein UNIX for Dummies Questions & Answers 4 03-06-2007 08:46 AM
Help Using Grep command to Find the string in the files in the root directory Subbu_Angeline AIX 3 01-17-2007 01:45 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 09-17-2008
BMC BMC is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 3
Find a string under a directory that is contained in another file

Hi I am loking for some help in writing a script that will take a number that is located in one file and search a folder structure for that string in any file under that directory. I can do this manually with :

find /"directory" -type f -exec grep -l 'Number String' {} \;

But now I will have to search for thousdands of numbers. All the number will be in one xls or csv file. I would also like to write all the results to a file so that we can go back and show each file/location that each of those strings hit. I'm sure this is an easy task but I am currently at a loss and any help would be greatly appreciated.
  #2 (permalink)  
Old 09-17-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
csv file, with numbers only in the fields
Code:
awk -F, '{ for(i=1; i<=NF; i++) {print $i} }' |\
while read number
do
       echo "searching ************************* $number"
       find /"directory" -type f -exec grep -l "$number" {} \;

done  > results.txt
  #3 (permalink)  
Old 09-17-2008
BMC BMC is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 3
Jim,

Please excuse my ignorance but where do I put in the file that contains all the numbers in your script.

Thank you
  #4 (permalink)  
Old 09-17-2008
BMC BMC is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 3
OK so of course after you post something it starts all coming back to you and I came up with this:

find /"directory" -type -f -exec grep -lf /"number file location" {} \; >> /tmp/results.txt

Now my only question is does anyone know a way to include the string that was currently being used with each line of data being sent back. I ran that command and got a list of the files that each of those numbers were in but no way to tell which number matched to which file. Again all help is appreciated.
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 05:05 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