我正在尝试用sed
另一个字符串替换一个字符串。我使用了下面的命令,它工作得很好,直到我运行cat index.html
并返回到旧字符串。有人可以帮忙吗?
<h1>
Hello World
</h1>
<p>This is out first WebDev study</p>
</body>
</html>
$ sed 's/Hello World/About Us/' index.html
<!DOCTYPE>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>
About Us
</h1>
<p>This is out first WebDav study</p>
</body>
</html>
$ cat index.html
<!DOCTYPE>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>
Hello World
</h1>
<p>This is out first WebDav study</p>
</body>
</html>
答案1
从手册页:
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX is supplied)
因此,在您的情况下,您只需要添加标志:
sed -i 's/Hello World/About Us/' index.html