I\'m trying to insert text to the third line in a file using sed, and the syntax I\'ve found on other forums is:
sed -i \'\' \"3i\\ text to insert\" file
A one-liner for OSX employing ANSI-C quoting:
sed -i '' '3i\'$'\n''text to insert' file
Adapted from https://stackoverflow.com/a/24299845/901597