Remove lines from the top and bottom of a file

September 21, 2016 - Uncategorized

If you need to remove the first X lines from the top and last Y lines from the bottom of a file, try:

Remove first X lines
tail +X file > file.2
Remove last Y lines from bottom of file
NOTE: this may not work on BSD Unix, i.e. MacOSX. Try using ghead via ‘brew install coreutils’
head -n -Y file.2 > file.3
Overwrite original file
file.3 > file

Leave a Reply

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