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.5. Modifying strings with substitute (&)

If you want to be able to append or modify a string, you can use the ampersand (&) command. The ampersand stores the pattern found so that you can recall it and then place it in the replacement string. That was a bit of a mouthful; here’s the layout on the modifier. Give it a normal substitute pattern to search for, then a pattern you want to append the first pattern with, followed by an ampersand. When the modifier is placed it is placed before the matched pattern. For instance, this sed statement 's/nurse/"Hello" &/p' will produce the following output:

						$ sed -n 's/nurse/"Hello" &/p' quote.txt 
The local "Hello" nurse Miss P.Neave was in attendance.
					

based on the following input line of text, ‘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