How to convert hex to ASCII characters in the Linux shell?
bash, encoding, linux, scripting, shell
Solution
echo -n 5a | perl -pe 's/([0-9a-f]{2})/chr hex $1/gie'
Note that this won't skip non-hex characters. If you want just the hex (no whitespace from the original string etc):
echo 5a | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie'
Also, `zsh` and `bash` support this natively in `echo`:
echo -e '\x5a'
Problem
Let's say that I have a string `5a`. This is the hex representation of the ASCII letter `Z`. I need to find a Linux shell command which will take a hex string and output the ASCII characters that the hex string represents. So if I do: ``` echo 5a | command_im_looking_for ``` I will see a solitary letter `Z`: ``` Z ```