I want to remove some n lines from the end of a file. Can this be done using sed?
For example, to remove lines from 2 to 4, I can use
$ sed
A funny & simple sed and tac solution :
n=4
tac file.txt | sed "1,$n{d}" | tac
NOTE
" are needed for the shell to evaluate the $n variable in sed command. In single quotes, no interpolate will be performed.tac is a cat reversed, see man 1 tac{} in sed are there to separate $n & d (if not, the shell try to interpolate non existent $nd variable)