![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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
|
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|