I am trying to compare two text in Unix. I tried the below. It didn’t work. In need to compare the first and last lines of a file.
firstline=`head -1 test.txt`
echo $firstline
lastline=`tail -1 test.txt`
echo $lastline
if [ $firstline == $lastline ]
then
echo "Found"
fi
Surely, am missing something. Please help.
Perhaps simpler…
Update to answer Jan’s questions.
I prefer
sedfor grabbing the first and last lines of a file because the same command-line works on Linux, Mac OS and Solaris. Theheadandtailcommand-lines are different between Linux and Solaris.