sed 命令 – sed 's/test/toast/' – 不替换文件中的所有 'test'

Hei*_*iko 2 sed

第二个“测试”行不应该也被替换吗?我将如何编写命令来替换所有“测试”?

$ sed 's/test/toast/' texttest.txt 
toast file test file hahahaha 1
toast file test file hahahaha 2
Run Code Online (Sandbox Code Playgroud)

Hei*_*iko 7

好的,我知道了 …

g 替换正则表达式的所有非重叠匹配项,而不仅仅是第一个匹配项。

$ sed 's/test/toast/g' texttest.txt 
toast file toast file hahahaha 1
toast file toast file hahahaha 2
Run Code Online (Sandbox Code Playgroud)