Print a Line Range With sed

Extract lines by number or pattern without loading the whole file into an editor.

LinuxtextscriptingcliLow risk
Run sed -n '1000,1050p' file to print lines 1000 through 1050.

01Command

Command
$ sed -n '1000,1050p' server.log

02What 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

RiskLow risk
RequirementsPreinstalled on Linux (GNU sed)
!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

Last verified: 2026-10-13 · Category: Developer

06Related solutions