sed: 1: "3i\\this is my new line3"
sed -i '' -e '3i\\
this is my new line 3' test.txt
dice@williscorto:~/test % cat foo.txt
1
2
3
4
5
6
dice@williscorto:~/test % sed -i '' -e '3i\\
this is my new line 3' foo.txt
dice@williscorto:~/test % cat foo.txt
1
2
this is my new line 3
3
4
5
6
You can use re_format(7) for substitute to matching the null string at the beginning of a line then insert text ending with \n[1addr]i\ expect new line.
sed -i '' -e '3s/^/line3\n/g' test.txt
Sed Functions
[2addr]s/regular expression/replacement/flags
$ cat <<EOS | /bin/ed -s sample.txt
> w sample.txt.bak
> 3i
> inserted line
> .
> wq
> EOS
$ diff -u sample.txt.bak sample.txt
--- sample.txt.bak 2020-11-10 03:42:54.362425000 +0000
+++ sample.txt 2020-11-10 03:42:54.362466000 +0000
@@ -1,5 +1,6 @@
1
2
+inserted line
3
4
5