Reputation: 55
I am trying to grep a particular pattern from a group of files stored in a directory thru shell script. However script scans through the files but it is not fetching me the result. I have 5 files with the pattern as finishing with status COMPLETE
Here is the code,could you please help on the issue
#!/bin/bash
dt=$(date --d='7 day ago' +'%Y%m%d')
countT=$("find /home/arun/file_status -type f -name "product_feed_*stock*_${dt}*.out" -exec grep "finishing with status COMPLETE" {} \;" | wc -l)
echo $countT
if [ $countT -eq 5 ]
then
echo "Hello"
else
echo "Hai"
fi
The below is the error:
find /home/arun/file_status -type f -name product_feed_stock_20170504*.out -exec grep finishing: No such file or directory 0 Hai
Upvotes: 0
Views: 624
Reputation: 143
Need to remove quotes in find command.
#!/bin/bash
dt=$(date --d='7 day ago' +'%Y%m%d')
countT=$(find /home/arun/file_status -type f -name "product_feed_stock_${dt}*.out" -exec grep "finishing with status COMPLETE" {} \;| wc -l)
echo $countT
if [ $countT -eq 5 ]
then
echo "Hello"
else
echo "Hai"
fi
Upvotes: 1