Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nepsilon/8352c67035f9e59a572794b5266bdbdb to your computer and use it in GitHub Desktop.
Save nepsilon/8352c67035f9e59a572794b5266bdbdb to your computer and use it in GitHub Desktop.
How to output a range of lines from a file? — First published in fullweb.io issue #107

How to output a range of lines from a file?

Easy enough with sed:

sed -n	123,230p filename

This will output filename content, from line 123 to line 230, inclusives. Notice the p letter after the last line number, this is what instruct sed to print to stdout.

A tip when working with large files: Add ;231q after 230p, to prevent sed to keep scanning until EOF (end of file). The whole command would then be:

sed -n	'123,230p;231q' filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment