O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.6. Writing to a file within sed

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required