Print a Line Range With sed
Extract lines by number or pattern without loading the whole file into an editor.
Run sed -n '1000,1050p' file to print lines 1000 through 1050.
01Command
Command
$ sed -n '1000,1050p' server.log02What it does
sed streams input and applies the address range to the print command, so pulling a section out of a multi-gigabyte log is instant and uses almost no memory. An editor would struggle or take minutes on such files, which is exactly why text streams are handled in the terminal.
03Risk
!Warning: Line numbers count physical lines; files with very long lines still count as one line each.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- sed.1.en.html manual page (Debian bookworm)Evidence: Documents address ranges with -n and the p command to print selected lines.
Last verified: 2026-10-13 · Category: Developer