Sed 使用正则替换内容文本,它的格式是 s/原来的内容/要替换的内容/
。
Hello world!
This is a test file.
1.1.2-a1b2c3d
你可以用以下命令来替换文件中的 world
为 Moto
¹:
sed -i -e "s/world/Moto/g" test.txt
替换后,文件的内容变为:
Hello Moto!
This is a test file.
1.1.2-a1b2c3d
你也可以用以下命令来替换文件中的 world
为 Moto
,但只替换第一个匹配到的内容¹:
sed -i -e "s/world/Moto/" test.txt
替换后,文件的内容变为:
Hello Moto!
This is a test file.
1.1.2-a1b2c3d