I am trying to use sed
to replace a string with another one. I used the below command and it worked just fine up until I ran cat index.html
and it went back to the old string. Can someone help, please?
<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>
xmlstarlet
if your html is valid xhtml). e.g. your sed script would fail if there was a linefeed or more than one space (or a<!-- comment -->
betweenHello
andWorld
(but would still render exactly the same in a browser. sed is a line-oriented tool, it does not deal well with structured text. HTML is not a line-oriented format, it is structured text. – cas Aug 12 '21 at 07:24