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.7. Reading text from a file

When processing a file, sed allows you to read from another file and append the text from that file to the current file, placing it after the line with the pattern match. The format is:

address r filename 

where ‘r’ lets sed know it’s going to read from another file source and ‘filename’ is the name of that file.

Let’s create a small file called sedex.txt. Here are the contents of the file:

						$ pg sedex.txt 
Boom boom went the music.
					

We are now going to append the file sedex.txt to the current working copy of our quote.txt file. We’ll put the contents of the file after the line where the pattern /company/ is matched, which is line 3. Please note that the filename we want to read stays enclosed by the single quotes. ...

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