For instance, the following one-liner uses the quit command to print the first ten lines from a file:
sed prints each line until it gets to line 10 and quits.
The previous version is much more efficient than its functional equivalent:
(especially if myfile is a long file) because sed doesn't need to keep reading its input once the patterns in the script are satisfied.
One possible use of q is to quit a script after you've extracted what you want from a file. There is some inefficiency in continuing to scan through a large file after sed has found what it is looking for. Thescript uses this technique.