Reputation: 1031
To execute 'find' with some variables from txt file i made this but it doesn't work. is that wrong with execute statement?
#/bin/bash
while read line;
do
echo tmp_name: $line
for ST in 'service.getFile("'$line;
do
find ./compact/ -type f -exec grep -l $ST {} \;
done
done < tmpNameList.txt
Upvotes: 1
Views: 359
Reputation: 414207
grep
can read multiple patterns from a file (-f
option):
find ./compact/ -type f -exec grep -f patterns.txt {} +
where patterns.txt
(prepend 'service.getFile('
to each line) is:
sed 's/^/service.getFile(/' tmpNameList.txt >patterns.txt
Upvotes: 0
Reputation: 121710
Try and quote $ST
in your find
command.
What's more:
./
is not necessary;you don't seem to have any special regex character (the (
needs to be quoted in grep
's classical regex mode, and I assume you did mean a literal dot), so use fgrep
instead (or grep -F
). Ie:
find compact/ -type f -exec fgrep -l "$ST" {} \;
Upvotes: 1