Say the file has ten lines:
We want to extract only lines five through eight from the file.
This isn't a hard problem, and there are probably a thousand ways to do this. However, I chose to use a simple sed command.
By typing the following we can get the result we want.
sed -n '5,8p;8q' filename
This line basically tells sed to start at line 5 and print until line 8 and then end processing at line 8. This simple construct works equally well with very large files and wider ranges of lines. Your output will look something like this:
It also works for extracting single lines if you change the line to look something like this:
sed -n '5p;5q' filename
The above line prints the single line (in this case "Line 5") and then stops processing the file.
I recommend the books Classic Shell Scripting by Arnold Robbins and Nelson H.F. Beebe and O'Reilly's Sed and Awk (second edition) by Dale Dougherty and Arnold Robbins if you would like additional resources for learning how to effectively leverage the sed utility.
How do you extract lines from a file? What tools and techniques work for you?