I have a to find for list of words in a list of files. Hence I have put the list of words in a file, and using for loop trying to read each word in a file and use find command to grep for that word in list of found files.
I am using the mentioned flavor of Linux
bash-3.1$ uname
HP-UX
And below mentioned is my shell script.
#!/bin/sh
PATH="/NO/20171013"
STRING=`/usr/bin/cat /home/test/STAT44_test.txt`
for LINE in ${STRING}
do
echo "find ${PATH} -type f -name \"*.txt\" -exec grep -w "${LINE}" {} \; 2>/dev/null | /usr/bin/wc -l"
LINES=`find ${PATH} -type f -name "*.txt" -exec grep -w "${LINE}" {} \; 2>/dev/null | /usr/bin/wc -l`
echo "LINES count is ${LINES}"
if [ ${LINES} -eq 0 ]
then
echo "In not found"
# echo "${LINE} is not found in ${PATH}" >> /home/test/STAT44_not_found.out
else
echo "In Found"
# echo "${LINE} is found in ${PATH}" >> /home/test/STAT44_found.out
fi
done
The find command find ${PATH} -type f -name "*.txt" -exec grep -w '${LINE}' {} \; 2>/dev/null works perfectly in the command prompt, whereas it is not at giving any output, if used in the shell script as mentioned above.
The output of echo $? is 0 but the find command doesn't produce any output.
The output of the script is
find /NO/20171013 -type f -name "*.txt" -exec grep -w 655044810645 {} \; 2>/dev/null | /usr/bin/wc -l
LINES count is 0
In not found
find /NO/20171013 -type f -name "*.txt" -exec grep -w 734729751028 {} \; 2>/dev/null | /usr/bin/wc -l
LINES count is 0
In not found
Actually the *.txt files under /NO/20171013 has files with pattern 655044810645 and 734729751028 . Hence the Word count should not be 0 and it has to get into else part.
What could be missing?