0

I had a script that failed, with the term "interlisted" in it. I needed to find it, so I swept though the directory tree looking for it. I did not find it.

That find should have found the script used.It should look at every file and preform a grep -H -l and list the name of the script that contains interlisted.

find /home/big_bank/ -type f -exec grep -H -l "*interlisted*" {} \; > /tmp/find_interlisted &
find /home/big-bank/ -type f -exec grep -H -l "*inter*" {} \; > /tmp/find2_interlisted &

Yet the script was 2 levels down from ${HOME} which was /home/big_bank/

$ cat  ${HOME}/scripts/stocks_script.ksh | grep interlisted

TS_INTERLISTED="${HOME}/data/interlisted_securities_${TRDDATE}.txt";
FINAL_OUTPUT_FILE3="interlisted_securities_${TRDDATE}.txt";
sqlplus -S $ETDHUB @${HOME}/data/sql/interlisted_query.sql | sort -t'|' -k1,1 | \

Could I have constructed the find statment better, did I make some mistake. I can't believe that the find did not find it.

This finds it.

grep -H -l -r "interlisted" /home/big_bank/*
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
capser
  • 2,442
  • 5
  • 42
  • 74
  • `*inter*` isn't a valid regex -- `*` changes the meaning of the term that immediately precedes it, so it's inherently illegal at the very front of the line (where there is no such preceding term). If you were grepping for `interlisted`, not `*interlisted*`, you'd be fine. – Charles Duffy Jun 11 '18 at 20:19
  • Thus, the difference between your working code and your broken code isn't the `find`, it's the `*`s. – Charles Duffy Jun 11 '18 at 20:20
  • BTW, it's more efficient to use `find ... -exec grep ... {} +`, not `find ... -exec grep ... {} \;`; the former calls `grep` once per file found, the latter passes each `grep` multiple names. There are some caveats there -- if you don't pass `-H` or `-h`, the number of files passed to each instance changes behavior; and if you have another `find` action after the `grep` that depends on whether a given file matches, processing each file individually is mandatory -- but they don't apply here. – Charles Duffy Jun 11 '18 at 20:25

0 Answers0