I have a directory full of files (100 files) and I want to be able to search for a string called "end" at the end of the files (last line or last 5 lines) and echo each file to say "incomplete" if not found.
This is what I have so far.
---
for file in 'ls';do
Incomplete='tail -5 $file | grep end';
if [[ $file -ne "$Incomplete" ]];then
echo "$file is incomplete.";
fi
done
The syntax error in the script is due to using apostrophes ' in lieu of backticks ` , so that Incomplete has the string contents tail -5 ... . Please note that backticks are deprecated, use the $(...) construct instead for "command substitution".
The comments on the semantics by jim mcnamara still apply.