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

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.