cat -n file
outputs file
with line numbering, but how can I specify at which line to start the numbering? Is there a command that can do that?
I've thought of perhaps splitting the process into a few commands. If I want to start line numbering at line N
of the text file file.txt
, then:
- Print the first
N-1
lines, à lahead -$((N-1)) file.txt
- Print the remaining
N
lines, numbered:tail -n N file.txt | cat -n
But the second step is not possible if the input is from stdin
; the first step will have consumed all of it. I'd have to create some temporary file to read from and then remove it, AFAIK.