Linux shell under 16 binary "\uxxxx" Unicode to UTF-8 Chinese

Source: Internet
Author: User

The issue occurs in the background:

There is a project through the IP to get the city needs of attribution, I was directly through the IP Attribution query interface of Sina to obtain. I'm using a shell script call

result=$ (curl-s ' http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=119.137.53.145 ')

Returns the value in JSON format:

var remote_ip_info = {"ret": 1, "Start":-1, "End":-1, "Country": "\u4e2d\u56fd", "Province": "\u5e7f\u4e1c",
"City": "\u6df1\u5733", "District": "", "ISP": "", "type": "", "desc": ""};

I used awk to intercept the 16 Unicode encoding for "\u6df1\u5733" to City.
But in the "\u6df1\u5733" into the Chinese time encountered trouble, Baidu search method is to use Iconv to convert to Utf-8 Chinese, but these methods have no effect.
Perhaps Iconv is just a character that turns characters into other character sets, while "\u6df1\u5733" is the position of the Chinese "Shenzhen" in the Unicode 16 encoding table of Chinese characters,
So to use Iconv to convert, you need to first "\u6df1\u5733" decoding into Chinese characters "Shenzhen", and then converted to other utf-8, GBK, gb2312 and other coding methods.
Iconv does not seem to decode this function.


Solution:
It took a lot of time to find a solution on the stack Voerflow website.
1. Install a uni2ascii-4.15-1.el6.rf.x86_64.rpm
2. You can then use Ascii2uni to name the conversion
ascii2uni -a U -q
  # 深圳
  

Linux shell under 16 binary "\uxxxx" Unicode to UTF-8 Chinese

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.