This is what the a
command does:
sed -e "/test message1/a\\
'testing testing'" < data
This command will:
Queue the lines of text which follow this command (each but the last ending with a \, which are removed from the output) to be output at the end of the current cycle, or when the next input line is read.
So in this case, when we match a line with /test message1/
, we run the command a
ppend with the text argument "'testing testing'
", which becomes a new line of the file:
'test message1'
'testing testing'
'test message2'
'test message3'
'test message4'
'test message5'
You can insert multiple lines by ending each of the non-final lines with a backslash. The double backslash above is to prevent the shell from eating it; if you're using it in a standalone sed
script you use a single backslash. GNU sed
accepts a single line of text immediately following a
as well, but that is not portable.