这里是第一张海报。
试图使用sed查找和替换单词。代码如下:

configFile=ConnectionConfig.xml
sed 's/30??\" authentication=\"someuniqueauthkey/'$1'\" authentication=\"someuniqueauthkey/' $configFile

我会这样运行文件:
./choosePort.sh 3001

当我运行这段代码时,不会出现错误,比如错误的regex格式,它不会替换任何内容,tempXml.xml的内容只是ConnectionConfig的内容,没有改变。
我想做的是识别30个数字中的3000-3099??我认为是什么意思做。
我试图更改的输入行是:
<host id="0" address="someip" port="3001" authentication="someauthkey"

提前谢谢。
(出于安全原因,文件中的Ip和authkeys被隐藏)。

最佳答案

使用[0-9]而不是?匹配单个数字。

sed 's/30[0-9][0-9]\" authentication=\"someuniqueauthkey/'$1'\" authentication=\"someuniqueauthkey/' $configFile

关于regex - 使用sed查找并替换一系列数字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8909023/

10-09 10:18