Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
805 views
in Technique[技术] by (71.8m points)

bash - Sed and UTF-8 encoding

In SSH (Putty) I'm using a command to replace some text in a file which is encoded in UTF-8

For example

cd ~/public_html/app/Config; sed -i 's/ADDRESS_SSH/l'adresse à été correctement intégréé/g' param.php;

In the file all is OK but when displaying in the browser the accents are strange When verifing the file param.php I found that it's encoding was changing from UTF-8 to Europe de L'Ouest

Same problem for .xml file too

Any help to use sed without changing the encoding or maybe to add an other ssh line for rencoding the php and xml files newly in UTF-8 ?

Best regards and thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to ensure that the issued sed command is UTF-8 encoded.

You can do this in one of two ways:

  1. Write the sed command to a file, ensure the file is UTF-8, and execute it as a script:

    file yourfile should say UTF-8 Unicode text.

    You can then run bash yourfile.

  2. Alternatively, change your terminal and shell settings to UTF-8

    printf à | wc -c must say 2, not 1.

    locale should list "UTF-8" or "utf8" in the LC_CTYPE line.

    You can then run the sed command straight from the terminal prompt.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...