[英]Using sed to find and replace a range of numbers
第一张海报在这里。
尝试使用sed查找和替换单词。 代码如下:
configFile=ConnectionConfig.xml
sed 's/30??\" authentication=\"someuniqueauthkey/'$1'\" authentication=\"someuniqueauthkey/' $configFile
我会像这样运行文件:
./choosePort.sh 3001
当我运行这段代码时,没有给出像正则表达式格式错误那样的错误,它什么也不会取代,并且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
首先,匹配的表达式必须为30..
而不是30??
然后,您似乎忘记了sed的-e
参数。
试试:
sed -e 's/30..\" authentication=\"someuniqueauthkey/'$1'\" authentication=\"someuniqueauthkey/' $configFile
这可能对你有用:
sed 's/30[0-9][0-9]\(" authentication="someuniqueauthkey\)/'$1'\1/' $configFile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.