开发者

Sed command causing asian characters to be printed to file

开发者 https://www.devze.com 2023-03-22 01:51 出处:网络
This is a follow up problem to a question I posed earlier. Basically when I do this: sed \'/Q/{ s/Q//g r /Users/ericbrotto/Desktop/question.txt

This is a follow up problem to a question I posed earlier. Basically when I do this:

sed '/Q/{
s/Q//g
r /Users/ericbrotto/Desktop/question.txt
}' Commision.txt

everything is fine, but the new output just prints to a console.

When I do this:

sed '/Q/{
s/Q//g
r /Users/ericbrotto/Desktop/question.txt
}' Commision.txt > newFile

the output prints to file, but my new string (the one that was properly replaced in t开发者_如何学Gohe previous output) now reads as a bunch of asian (I believe Mandarin) characters.

Any ideas?


It sounds like you have an encoding mismatch.

I wager that your shell, Commision.txt and question.txt don't all have the same encoding. Because of that, sed is replacing part of a wide character that it doesn't recognize as wide. All subsequent character encodings are off by half a character, and the result is Chinese.

See this question for discussion of a similar problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消