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
Here's how to do it in one line syntax
sed -i '' -e "2s/^//p; 2s/^.*/text to insert/" file
duplicate second line: 2s/^//p;
2s/^//p;
replace new line with your text: 2s/^.*/text to insert/
2s/^.*/text to insert/