Ricky Ricky - 3 months ago 7
Bash Question

Need help in solving "unexpected end of file" exception?

I am trying to transform below 2 statements into a shell script

cat all5.log | grep 'Opened\|Closed'> all.log
awk -F ' ' '{print }' all.log | sort | uniq > uniqueFiles.txt

Here is monitorFd.sh bash script


if [ "" != "" ]; then
cat | grep 'Opened\|Closed' > temp.log
awk -F ' ' '{print }' temp.log | sort | uniq > uniqueFiles.txt

while IFS='' read -r line || [[ -n "$line" ]]; do
cmd1=`cat | grep Opened | grep $line | sort | wc -l`
cmd2=`cat | grep Closed | grep $line | sort | wc -l`
echo 'Opened: '$cmd1', Closed: '$cmd2' '$line
done < "uniqueFiles.txt"

rm -f temp.log
echo "No target file provided. (hint: trace dump of file-leak-detector.jar)" #syntax error: unexpected end of file

In notepad++ I changed this file to be of UNIX format. Also changed permission to +x, but I am getting below exception.

monitorFd.sh: line 16: syntax error: unexpected end of file

enter image description here

What is wrong with this program?


The Syntax for if in bash is if ... else/elif ... fi. So just add a fi at the end of your file.