2016-09-27 4 views

答えて

4

$ echo "$old" 
this paragraph 
yes, I'm going 
to be replaced 

$ echo "$new" 
New contains, 
I'm replacement! 

にあなたはbashの変数と使用パラメータに(それがinfileと呼ばれると仮定した場合)ファイルを読むことができるよう、あなたの新しい、古い段落を含む変数を持っていると仮定すると、拡張:

$ contents=$(< infile) 
$ echo "${contents/$old/$new}" 
bala bala ba1 
balabala. 
leave me here. 

New contains, 
I'm replacement! 

The rest contains 
should not be replaced. 

インプレースでファイルを変更するには

echo "${contents/$old/$new}" > infile.tmp && mv infile.tmp infile 
+0

はい!ありがとう、あなたは私の日を救う! – user3593261

関連する問題