Websitetemplate.org

Welcome > Linux > sed Magic > sed: Line deletion

sed: Line deletion

# delete the last line of a file 
sed '$d' 
# delete the last 2 lines of a file 
sed 'N;$!P;$!D;$d' 
# delete the last 10 lines of a file 
sed -e :a -e '$d;N;2,10ba' -e 'P;D'  # method 1 
sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2 
Ref: http://www.student.northpark.edu/pemente/sed/sed1line52.txt

Content Copyright 2003-2014 George Toft