Need a script

Hi All,

I'm new to Shell scripting.

I need a script, that reads the last line of a file(name is passed as a command line argument) and checks if last line has 'END OF FILE' in it or not.

If it does not have 'END OF FILE' in it, then it should exit.

Could anyone help me with the script.

Thanks.

Please familiarise yourself once again with the Forum Rules and Guidelines, regarding the subject title and how you should post questions.

What have you tried up to now?

I'll give some hints.

use tail, $1 and grep.

That's all you should need. Let us know what you've tried so far.

You can use While loop too.

while read line
do
    echo $line
    
done < "filename_here"

tail -1 filename | grep 'END OF FILE'

If the the string is found in the last line then the last line will be displayed else no result is displayed.

amit="END OF FILE"

ARS=`tail -1 $filename`

if [ "$ARS" == "$amit" ]
then
echo "file is ok"
else

echo "file NOT ok"
fi

Try this:

tail -1 $1 | grep -q 'END OF FILE' || exit 131
[[ $(tail -1 "$1") =~ "END OF FILE" ]] && echo ok || echo KO