Improving find to read table name from file

Hi there,
I currently use the following find command to recursively search all the subdirectories in our file system for a table ( in this case BB_TENURE_DAYS)

find -type f -exec grep -l "BB_TENURE_DAYS" {} \+

So I have this so far - the problem is how do I read the line to get the tablename

]

for line in `cat /tmp/$$controlFilesFound.txt`
        do
          #get filename some how
      
          find -type f -exec grep -l "$filename" {} \+
        done

how do I pick the filename up - it is the only field in the file

Many thanks
Rob..

grep can be made to work on all files in a directory, so (something like) this might speed things up:

find . -type d -exec grep "BB_TENURE_DAYS" {}/* \;

In this case it lands on <stdout>, so you can pick it up by a simple redirection, pipeline or something such:

for .... ; do
     .....
done > /some/file

for .... ; do
     .....
done | read VAR

But your loop is a little flawed. Consider:

while read line ; do
     [....]
done < /tmp/$$controlFilesFound.txt

instead. I usually add provisions to be able to add comment lines like in shell so that i can put notes for myself into the config files. I also filter out empty lines and whitespace prior to reading the file ("<b>" and "<t>" is a literal blank and tab character) This looks like:

sed 's/#.*//;s/^[<b><t>]*//;s/[<b><t>]*$//;/^$/d' /tmp/$$controlFilesFound.txt |\
while read line ; do
     [....]
done

I hope this helps.

bakunin

1 Like

many thanks - it's been a while since I have done unix stuff - it's all coming back to me 0:(