Reputation: 1564
I'm trying to insert this text...
"error.emailNotActivated":"This email address has not been activated yet."
... at line number 5 using sed.
Here is my command so far
translated="This email address has not been activated yet.";
sed -i '' -e '5i\'$'\n''"error.emailNotActivated":'"\"$translated\"" local.strings;
I unfortunately keep getting the error message "invalid command code T". It seems that sed is interpreting the colon as part of a command. Any suggestions how i can avoid this?
EDIT: Seems like an update error (working with old file d'oh...) the above expression works fine as do the other suggestions.
Upvotes: 0
Views: 3112
Reputation: 203393
Why are you fighting with sed for this? It's trivial in awk:
awk -v line='"error.emailNotActivated":"'"$translated"'"' '
NR==5{print line} {print}
' file
or:
awk -v line="\"error.emailNotActivated\":\"${translated}\"" '
NR==5{print line} {print}
' file
Upvotes: 3
Reputation: 45652
Are you looking for something like this?
$ seq 1 5 > file
$ cat file
1
2
3
4
5
$ translated="\"error.emailNotActivated\":\"This email address has not been activated yet.\""
$ echo $translated
"error.emailNotActivated":"This email address has not been activated yet."
$ sed -i "5i $translated" file
$ cat file
1
2
3
4
"error.emailNotActivated":"This email address has not been activated yet."
5
Upvotes: 1