将SED与通配符一起使用 [英] Using SED with wildcard

查看:1320
本文介绍了将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆