Linux sed and awk Cheat Sheet/Print a line range only

Show lines 5 through 10.

Section: sed Line Deletion and Printing

Print a line range only

bash
bash
sed -n '5,10p' file.txt
Explanation

A compact way to inspect a specific segment of a file.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing sed Line Deletion and Printing
Print only matching lines
Use sed as a pattern filter.
OpenIn sheetbashsame section
Delete a line range
Remove lines 5 through 10.
OpenIn sheetbashsame section
Delete blank lines
Remove empty lines from output.
OpenIn sheetbashsame section
Delete comment lines
Skip lines that begin with `#`.
OpenIn sheetbashsame section
Replace first occurrence per line
Substitute one match in each line.
OpenIn sheetbash1 tag match
Replace all occurrences per line
Substitute every match on each line.
OpenIn sheetbash1 tag match