To display a single line from a large text file:
The p
command prints matching lines, and the q
command causes sed to quit after the first match.
You can’t use q
if you want to print a block of lines, so you’ll just need to ^C
after the output is printed so that sed doesn’t keep needlessly reading the file.
If you want to replace a single line, you can use a similar trick (once you’ve identified the line number):
It may be advisable to use single quote here, rather than double quotes + variable substitution, to prevent shell weirdness. Unfortunately, there’s really no way to tell when this command has finished (except to let it work through the whole file).