寻找Perl或sed one-liner用另一个文件中的内容替换字符串

dr *_*rry 2 string perl replace sed file

在一个HTML文件中,让我们调用它index.html,我想用一个//gac goes here名为gac.js的单独文件替换一个注释字符串,例如,内容(多行).那有一个很好的单行吗?

我找到了一些东西:sed -e "/$str/r FileB" -e "/$str/d" FileA但它没有像承诺的那样工作.

我确实喜欢它尽可能短,因为它将在SVN恢复后调用(我不希望任何google.script污染我的开发环境).

Cha*_*ens 5

这应该有效,即使它是令人讨厌的:

perl -pe 'BEGIN{open F,"gac.js";@f=<F>}s#//gac goes here#@f#' index.html
Run Code Online (Sandbox Code Playgroud)

gac.js应该是动态的情况下:

perl -pe 's#//(\S+) goes here#open+F,"$1.js";join"",<F>#e' index.html
Run Code Online (Sandbox Code Playgroud)