0

このテキストを挿入しようとしています...

"error.emailNotActivated":"This email address has not been activated yet."

... sedを使用して5行目。

これまでの私のコマンドは次のとおりです

translated="This email address has not been activated yet.";
sed -i '' -e '5i\'$'\n''"error.emailNotActivated":'"\"$translated\"" local.strings;

残念ながら、「無効なコマンド コード T」というエラー メッセージが表示され続けます。sed はコロンをコマンドの一部として解釈しているようです。これを回避する方法はありますか?

編集:更新エラーのようです(古いファイルで作業しています...)上記の式は、他の提案と同様に正常に機能します。

4

2 に答える 2

3

なぜあなたはこれのためにsedと戦っていますか?それは awk で簡単です:

awk -v line='"error.emailNotActivated":"'"$translated"'"' '
NR==5{print line} {print}
' file

また:

awk -v line="\"error.emailNotActivated\":\"${translated}\"" '
NR==5{print line} {print}
' file
于 2013-04-22T16:18:24.257 に答える
1

このようなものをお探しですか?

$ 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
于 2013-04-22T15:53:17.900 に答える