To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
Say I've got a bunch of files that are all >100 lines long. I'd like to trim off the top 14 lines and the bottom 9 lines, leaving only the lines in the middle. This command will trim off the top fourteen:
cat myfile.txt | tail -n +15
Is there another command I can pipe through to trim off the bottom 9 without explicitly passing the length of the file?
Edited to add: My version of head (Mac OS 10.5) doesn't accept a negative number of lines as a parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With