[sed] Print a range of lines

Created on November 30, 2026

Use -n to suppress automatic output, then use p to print the addressed lines. In 2,4p, 2,4 selects lines 2 through 4.

sed -n '2,4p' dummy.txt

Example dummy.txt

one
two
three
four
five

Output

two
three
four

Without -n, the selected lines also appear in the normal output, so those lines are printed twice.

Bash Shell command sed