The following adds one line after SearchPattern
.
sed -i '/SearchPattern/aNew Text' SomeFile.txt
It inserts New Text
one line below each line that contains SearchPattern
.
To add two lines, you can use a \
and enter a newline while typing New Text
.
POSIX sed requires a \
and a newline after the a
sed function. [1]
Specifying the text to append without the newline is a GNU sed extension (as documented in the sed
info page), so its usage is not as portable.
[1] https://unix.stackexchange.com/questions/52131/sed-on-osx-insert-at-a-certain-line/