Search code examples
regexsedgrepcorruption

sed: cannot seem to match pattern to line


If I have sed script like this:

 35185222p

And run it as:

sed -n -f seddy.sed infile.xml

It correctly prints out the dodgy line of XML I want to fix.

If I change my script to:

 35185222s@^.*$@<load address='11b38c56' size='08' />@p

It doesn't make the match (ie no output is made). What have I got wrong?

OK: I think I get this now - unfortunately the corruption in this line in the original file means characters won't match to a . - so how do I fix that?

Further update This is what the line looks like when I cut and paste it:

  <load address='11c1�����ze='08' />

Solution

  • The real issue appears to be a clash of locales.

    Running

    LANG=c sed -f seddy.sed input.xml
    

    Fixes the problem. Of course, I could have used the c command instead.