Hi,
I have a file from which I need to remove the last n lines.
I was successful in removing only the last line using :
sed '$d' file_name
Could you please help me with the command.
Thanks,
H2
Hi,
I have a file from which I need to remove the last n lines.
I was successful in removing only the last line using :
sed '$d' file_name
Could you please help me with the command.
Thanks,
H2
sed "$((`wc -l f3|awk '{print $1}'`-3)),$ d" f3 #f3 filename
crazy one which i wouldn't suggest but works...
An awk version:
awk 'NR>c{print A[NR%c]} {A[NR%c]=$0}' c=4 file
Or if c<=0 (modulus fails,of coarse if c=0, just use cat):
awk 'NR>c{print A[NR-c]?A[NR-c]:$0} {A[NR]=$0}' c=4 file
the unix command "head" is made for that type of operation. Use the following operation.
to remove the last two line of a file use:
head -n-2 yourfile
@ scottazz : classic...
Only works on some systems.