i如果字符串中存在破折号,则“grep -w”不是唯一的。我该如何解决这个问题?
例子:
文件1:
足球01 足球
01测试
# grep -iw ^football01
football01
Run Code Online (Sandbox Code Playgroud)
文件2:
足球01
足球01-测试
# grep -iw ^football01
football01
football01-test
Run Code Online (Sandbox Code Playgroud) 我试图用正则表达式(sed)剪切(替换)一个字符串,但想要匹配第一次出现.在结果中,您可以看到它在第三个DATA处停止.
文本:
Cool Text Cool Text DATA : first text DATA : second text DATA : third text
Run Code Online (Sandbox Code Playgroud)
正则表达式:
sed 's/.*DATA//'
Run Code Online (Sandbox Code Playgroud)
结果:
: third text
Run Code Online (Sandbox Code Playgroud)