I was trying to remove all the lines of a file except the last line but the following command did not work, although file.txt is not empty.
$cat file.txt |ta
tmp=$(tail -1 file.txt); echo $tmp > file.txt;