简体   繁体   English

如何将UTF-8转换为Unicode

[英]How to convert UTF-8 to Unicode

I have some file with encoding utf-8 like this 我有一些编码为utf-8的文件,像这样

están están

and I want to convert it to something like this 我想把它转换成这样

\e\s\t\á\n \\ u0065 \\ u0073 \\ u0074 \\ u00E1 \\ u006E

How can I make this conversion in bash ? 如何在bash中进行此转换? I installed iconv but I did not managed to convert this 我安装了iconv,但没有成功转换

With Ruby you can have: 使用Ruby,您可以:

ruby -e "print File.read(ARGV.shift).unpack('U*').map{ |i| '\u' + i.to_s(16).upcase.rjust(4, '0') }.join" your_file

Or for strings: 或对于字符串:

ruby -e "puts ARGV.shift.unpack('U*').map{ |i| '\u' + i.to_s(16).upcase.rjust(4, '0') }.join" "your string"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM