How to use iconv or similar to convert a UTF-16BE string to human readable characters

219 Views Asked by At

I have the following data in UTF-16BE:

00 33 00 33 00 30 00 33 00 20 00 43 00 39 00 32 00 00 

I am trying to convert this to human readable format for further use in a bash script.

The above should resolve to "3303 C92"

Currently I've made it this far but im obviously getting something wrong.

iconv -f UTF-16BE -t ASCII /home/code.txt #string above is only thing in this file. 

command error: iconv: illegal input sequence at position 0

I am using RHEL 7

1

There are 1 best solutions below

0
Arnaud Valmary On

The last byte (00) is extra.

> base64 -d <<<"ADMAMwAwADMAIABDADkAMgA=" | iconv -f utf-16be -t ascii
3303 C92iconv: incomplete character or shift sequence at end of buffer

After removing last byte:

> base64 -d <<<"ADMAMwAwADMAIABDADkAMg==" | iconv -f utf-16be -t ascii
3303 C92