Objective: Read a file from a specific line number or skip the first x numbers of lines.
To read a file starting from a specific line, the tail command can be used. To read a file from line 5 onwards, use the following syntax.
1 |
$ tail -n +5 /path/to/file |
The “+5” offset argument to tail tells it to output lines from the 5th line till the last line of the file.
To get the same result using sed
, use the following syntax.
1 |
$ sed '5,$!d' < /path/to/file |
The parameter “5,$” means from line 5 till end of file. The exclamation mark “!” will select all lines that do not match. And finally “d” is to delete the line.