質問

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' />
役に立ちましたか?

解決 2

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.

他のヒント

Try the sed c command to change the contents of the line:

35185222c\<load address='11b38c56' size='08' />

I frankly don't know why the regex ^.*$ would not match on that line. My guess is that it has something to do with your locale and character encodings, but it seems like it has to be a bug either way.

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

^ and $ should be escaped or between [ ] at least if not, there meaning (^ = begin, $ = end) is used and there is nothing before a begining nor after a end.

be carrefull also with the ', it depend of your string delimiter from your sed and must mybe are escpaed too

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top