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
You can use sed to delete all lines but the last from a file:
sed -i '$!d' file