Sample Header Ad - 728x90

Negative arguments to head / tail

25 votes
3 answers
21772 views
Variants of this question have certainly been asked several times in different places, but I am trying to remove the last M lines from a file without luck. The second most voted answer in this question recommends doing the following to get rid of the last line in a file: head -n -1 foo.txt > temp.txt However, when I try that in OSX & Zsh, I get: head: illegal line count -- -1 Why is that? How can I remove the M **last** lines **and** the **first** N lines of a given file?
Asked by Amelio Vazquez-Reina (42851 rep)
Nov 20, 2014, 05:17 PM
Last activity: Nov 30, 2022, 01:37 PM