Last Updated: February 25, 2016
· scornelius

Print particular lines from a file using sed

Output the nth line of a file:

sed -n '20p;20q' < filename.ext

The '20p' part says print the 20th line. The '20q' part says stop searching the file at the 20th line - if you don't include this it will continue searching through the file until it reaches the end.

To output the nth to the mth lines:

sed -n '20,30p;30q' < filename.ext

Prints the 20th to the 30th lines.