As well as using the ‘>’ file redirection to send output to a file, you can send the results from a sed command to a file. The format for this is a little like the write using substitutes. Here’s the format:
[ address[,address]] w filename
where ‘w’ lets sed know it’s going to write the results to a file, and ‘filename’ is the filename is self-explanatory. It’s straightforward; here are a couple of examples.
$ sed '1,2 w filedt' quote.txt
Here the file is sent to the screen, and the pattern range, which is lines 1 and 2, is sent to the file called filedt.
$ pg filedt The honeysuckle band played all night long for only $90. It was an evening of splendid music and company.
In this example we search for the ...