使用带通配符的 SED [英] Using SED with wildcard
本文介绍了使用带通配符的 SED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用通配符替换一个字符串,但它不起作用.
I want to replace a string with wildcard but it doesn't work.
字符串看起来像some-string-8"
The string looks like "some-string-8"
我写的
sed -i 's/string-*/string-0/g' file.txt
但输出是
some-string-08
推荐答案
星号 (*) 表示前一项的零个或多个".
The asterisk (*) means "zero or more of the previous item".
如果你想匹配任何单个字符使用
If you want to match any single character use
sed -i 's/string-./string-0/g' file.txt
如果你想匹配任何字符串(即任何单个字符零次或多次)使用
If you want to match any string (i.e. any single character zero or more times) use
sed -i 's/string-.*/string-0/g' file.txt
这篇关于使用带通配符的 SED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文