-3

basically what I want to do is use SED (linux version) to make changes in a HTML file. When I execute that code, i get an "unknown command" error because sed can't tell what whitespace or line breaks are apparently.

sed 's|<a href="es/map-button.html">
            <div class="map-button">|<div id="confirmation" onclick="confirmation()" class="map-button">
            <script type="text/javascript">
<!--
              function confirmation() {
                var answer = confirm("Access map? (uses internet)")
                  if (answer){
                    window.location = "google.maps.com";;
                  }
                  else{
                    //alert("Returning to current content")
                  }
              }
//-->
            </script>|g' *.html

my delimiters are the "|" that you see here.

Leo Nahr
  • 1
  • 1
  • What is the question? What is the problem you are facing? – Fazlin Jul 20 '16 at 11:47
  • Sorry should have specified more. Basically when I execute that code, i get an "unknown command" error because sed can't tell what whitespace or line breaks are apparently. – Leo Nahr Jul 20 '16 at 11:55
  • Strange, I get the error "unterminated 's' command", which is due to the fact that the arguments to the `s` command must not contain literal newlines. – Michael Vehrs Jul 20 '16 at 15:28
  • you cannot just using sed like this. sed only read one line to pattern space at a time. – Lee HoYo Jul 21 '16 at 16:28

1 Answers1

0

Using the change command of sed.

sed '/<a href="es\/map-button\.html">/{
    N
    /<div class="map-button">/c\
<div id="confirmation" onclick="confirmation()" class="map-button">\
<script type="text/javascript">\
<!--\
function confirmation() {\
    var answer = confirm("Access map? (uses internet)")\
    if (answer){\
        window.location = "google.maps.com";;\
    }\
    else{\
        //alert("Returning to current content")\
    }\
`}\
//-->\
</script>
}' *.html

/address/c\
text

Delete the pattern space. With 0 or 1 address or at the end of a 2-address range, text is written to the stan-dard output

Lee HoYo
  • 1,217
  • 9
  • 9