How do I Find a string in a file and place a string above it?
s/…/…/ is a substitution, replacing the first … with the second …. You can use a new line in your string to insert text above or below a line break.



sed -i -e 's/__MARKER__/Hello world\
__MARKER__/' someFile.txt


Escape the new line with a backslash, else you'll get "unescaped newline inside substitute pattern". To type a new line in Terminal, use ⌥↩︎.

You can use &amp; as shorthand for the match, so you don't need to retype it in the replacement.

sed -i -e 's/__MARKER__/Hello world\
&amp;/' someFile.txt