I am having a directory in which it contains 20 sub-directories and all sub-directories names end with "_b". In each sub-directory same file name "error.txt" is there. I need to loop-in to all the sub-directories and grep for a word called "ECHO" in the "sub-directory/error.txt" file and if the word is present I need to execute statement one, if the word "ECHO" is not present in file "sub-directory/error.txt" I need to execute statement two. I tried like this:
#!/bin/bash
File="./error.txt"
for d in *_b;
do
if grep -q "ECHO" "$File"; then
echo "$d:";
Statement 1
echo "------------------";
else
echo "$d:";
Statement 2
echo "------------------";
fi
done
But I am not getting the desired output , I am getting output as :
grep: ./error.txt: No such file or directory
echo "$d:";to before yourif-elseand theecho "------------------";to after it. You don't need the;s btw.