Use sed to Insert Text After Given Line

sed -i '/existing line/a text to be inserted' filename

The above will search the file “filename” for the line “existing line” and then add after it the text “text to be inserted”. Tested on Ubuntu. Fails, as is at least, on OS X as the latter’s version of sed requires a file extension when using the -i flag.

From a post by colucix at

“the a (add) command of sed adds the specified text immediately below the line containing the pattern. The -i option edits the file in place so that you can avoid temporary copies.”