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 '2,4d' file
But I don't know the line numbers. I can delete the last line using
$sed $d file
but I want to know the way to remove n lines from the end. Please let me know how to do that using sed or some other method.
To delete last 4 lines:
A funny & simple
sed
andtac
solution :NOTE
"
are needed for the shell to evaluate the$n
variable insed
command. In single quotes, no interpolate will be performed.tac
is acat
reversed, seeman 1 tac
{}
insed
are there to separate$n
&d
(if not, the shell try to interpolate non existent$nd
variable)