Ubuntu – How to get UTF8 from a hex variable

character encodingUbuntu

I'm debugging an app for a client and I found the information from the DB which could be solution. I ask the client to extract it but unfortunately the client sent me the raw data in hexadecimal…

I ask the client to resend me the plain text from the DB tools but awaiting their response I'm looking for a bash solution.

I know the encoded data is a UTF-8 encoded string: is there a way to decode it with Unix tools?

Best Answer

With xxd (usually shipped with vim)

$ echo 5374c3a97068616e650a | xxd -p -r
Stéphane

If your locale's charset (see output of locale charmap) is not UTF-8 (but can represent all the characters in the encoded string), add a | iconv -f UTF-8.

If it cannot represent all the characters, you could try | iconv -f UTF-8 -t //TRANSLIT to get an approximation.

Related Question