-1

假设我在以下目录中 A/B/C/prop,需要检查 其他 100 个文件中的文件。在这两个文件中,我有以下条目e0e1

$DBConnection_target=targetname
$DBConnection_source1=sourcename

我只需要更改将要使用targetnamesourcename字符串,取自键盘(读取)。这些字符串可能出现超过 2-3 次。

4

1 回答 1

2

您可以使用sed和 来执行两个文件中的替换e0e1如下所示:

# set what you want the source and target to be changed to here:
newSource=foo 
newTarget=bar

sed -i 's/\($DBConnection_target\)=.*$/\1='"$newTarget"'/;s/\($DBConnection_source1\)=.*$/\1='"$newSource"'/' e0 e1
于 2013-04-30T12:28:41.990 回答