Quote:
Code:
sed -e '4a\Option "InvertX" "1"' temp.txt
|
The above command works on my system.
Code:
$ cat temp.txt
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
$ sed -e '4a\Option "InvertX" "1"' temp.txt
Line 1
Line 2
Line 3
Line 4
Option "InvertX" "1"
Line 5
Line 6
So, that begs the question: are you showing the
real, actual command you are using? Or did you modify it when you posted the questions?
Similarly, are you using the command
exactly as you describe?
EDIT:
1. On the off-chance that it's a misunderstanding on how sed works: sed
does not modify the file by default. Sed prints the result of the modification(s) to the screen unless you explicitly tell it to do otherwise. You can tell it to do otherwise using output redirection (just like you did with your awk command) or use the '-i' option with sed (which tells sed to modify the original file). If you use the '-i' option, then read the man page for sed (
man sed) regarding that option and how you can make an automatic backup of the file (in case your sed instructions don't give you what you want).
2. Regarding your awk command... Fix it by escaping the internal double quotes:
Code:
awk 'NR==4{print "Option \"InvertX\" \"1\""}1' temp.txt > temp2.txt
NOTE: The results of the two commands you gave are
different. Your sed command adds the new text after the
4th line (as shown in my sample output)--because you are "appending" the text on the fourth line (i.e. the '4a' in the command).
Compare that with the awk command that adds the new text after the
3rd line.
If the exact line matters, then make sure you use the appropriate command (or modify it accordingly).