Append a line of text after a line matching a pattern

Let's say we've got:

$ cat file.txt
1
2
3
4
5
6
7
blah
blah blah
append after me
blah bleh!
append after me
blah blah blah
bleeeh

This will add "new stuff" after every line that says "append after me":

$ sed -i '/append after me/a new stuff' file.txt

Bingo:

$ cat file.txt
1
2
3
4
5
6
7
8
9
blah
blah blah
append after me
new stuff
blah bleh!
append after me
new stuff
blah blah blah
bleeeh

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).