0

I wanna to find and replace a tag with inner html and replace it with something. I use this command but it has problem in regex.

find pages* -type f -exec sed -i -e 's/\(<div class=\"IASBS_Date_en\">\)[.]\(<\/div>\)/Sallam Karim/g' {} \;

what should I write instead of [.] Thanks.

Karim Pazoki
  • 951
  • 1
  • 13
  • 34

1 Answers1

4

Don't parse XML/HTML with regex, instead use a proper parser like with a expression :

Example

File :

<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <a>foo</a>
        <div class="IASBS_Date_en">20180219</div>
        <b>bar</b>
        <c>base</c>
    </body>
</html>

Command :

xmlstarlet edit -L -u '//div[@class="IASBS_Date_en"]' -v '20190101' file.html

Edited file :

<!DOCTYPE html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <a>foo</a>
    <div class="IASBS_Date_en">20190101</div>
    <b>bar</b>
    <c>base</c>
  </body>
</html>

You just have to replace your command with this one

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223