-
Today, I needed to script removing the last couple lines of a file from the shell. The
head
command shipped by macOS doesn't support-n -2
But theirtail
command totally supports-n +3
tac myfile.txt | tail -n +3 |tac
-
Ugh. I don't actually have 'tac' by default on macOS.
-
Sigh. time for the trivial perl script.
-
On second thought. cat file.txt | sed '$d'| sed '$d' is inelegant but unambiguous.