Shell Using sed -i to write to a text file

Greetings.
I'm simply attempting to insert a line of data into a text file at specific line.
Examples I've located elsewhere indicate the command should be something like this:

sed -i '1i\testtext' temp.txt Whereas this command would insert phrase testtext at line 1 of file temp.txt and....

sed -i '2i\testtext' temp.txt would insert phrase testtext at line 2 of file temp.txt.

Entering the command as such results in:
sed: 1: "temp.txt": undefined label 'emp.txt'
Which indicates that I'm missing a slash or backslash perhaps?

I cannot seem to find a solution to this seemingly obvious problem on the forum or elsewhere.
The man page for sed indicates that syntax for the i command is [1addr]i\ but i cannot find any mention of closing the command before the file name.

This is my first post, I apologize in advance for my ignorance :)
 
I guess I don't understand at all. I simply need to send a line of text to a specific line in the file. It would be similar to echo "test" > test.txt but instead to a specific line such as the 20th line etc.
 
Also, if, say, you have to work with scripts written for Linux, there is also gsed in packages. So, in such a case, it might be easier to go through a specific script and substitute gsed for sed in such a script. Either that or making any instance of sed -i, sed -i ''

(There has to be some silly pun here about that's what I sed, but I'll spare the forum my aging sense of humor)
 
Back
Top