【发布时间】:2017-01-10 10:03:27
【问题描述】:
我在 bash 中使用 sed 来尝试替换所有匹配的字符串:
compile 'com.test.*:*'
与:
compile 'com.test.*:+'
其中 * 是通配符。
我的文件是这样的,叫做 moo.txt:
compile 'com.test.common:4.0.1'
compile 'com.test.streaming:5.0.10'
compile 'com.test.ui:1.0.7'
我希望它看起来像这样:
compile 'com.test.common:+'
compile 'com.test.streaming:+'
compile 'com.test.ui:+'
我尝试过像这样使用 sed:
sed -i -- "s/compile \'com.test.*:.*\'/compile \'com.test.*:+\'/g" moo.txt
但这会使文件看起来像:
compile 'com.test.*:+'
compile 'com.test.*:+'
compile 'com.test.*:+'
知道如何在替代字段中正确使用通配符吗?
【问题讨论】:
-
查找捕获组。