以下に例を示します。
UnixとSed初心者はここにあります! 要件があり、サフィックスを追加する必要があります。「あきらめる」レポートの行に一致する文字列が含まれている場合。一致する文字列が他のファイルの一部です。「放棄.txt」。私はまた、主要なレポートのコピーについてこれらのことを行ってみました。 以下に例を示します。 レポートは次のとおりです。 i love apple_tart as a desert banana is full of potassium and iron there are so many helath benefits of apple eating the king of fruit is mango there are apple_pie of many variety これが方法ですあきらめるtxt良い: apple_pie banana これは同じファイルから私が望む期待される出力です。 i love apple_tart as a desert banana is full of potassium and iron,waive there are so many helath benefits of apple eating the king of fruit is mango there are apple_pie of many variety,waive 私が試したスクリプトは次のとおりです。無効な変数名 間違い #!/bin/csh -f if (-r fruits_bkup.txt) then rm fruits_bkup.txt endif yes|cp fruits.txt fruits_bkup.txt foreach word ("`cat waiver.txt`") sed -i "/${word}/s/$/ ,waived/" fruits_bkup.txt end sedコマンドで二重引用符を一重引用符に置き換えると、レポートに何の変更もありません。 ありがとうございます! 私は期待した: i love apple_tart as a desert banana is full of potassium and iron,waive there are so many helath benefits of apple eating the king of fruit is mango there are apple_pie of many variety,waive 得る: 無効な変数名 間違い