bash – remove first line with tail and last line with head

Say you have a file called test.txt:

line 1
line 2
line 3

Remove the first line:

tail -n +2 test.txt

Remove the last line:

head -n -1 test.txt

Remove both:

tail -n +2 test.txt | head -n -1

Simple, portable, works on any Unix system.

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *