Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
On 12/25/2014 09:04 PM, Bob Proulx wrote:
> I have a string of hex encoded us-ascii characters. The hex sequence
> 48 61 70 70 79 is obviously "Happy". Is there an easy way to convert
> them to ascii using printf? It seems like there should be.
>
> $ printf "%c\n" 0x48 0x61 0x70 0x70 0x79
> 0
> 0
> 0
> 0
> 0
> [...]
> Is there any way to use the shell printf like the C printf and do this
> conversion in the coreutils printf? Or perhaps another way?
I only know of the double-folded printf way via octal:
$ env printf $(env printf '\\%03o' 0x48 0x61 0x70 0x70 0x79)
Happy
(The additional 'env' is to force the use of coreutils printf rather
than that of the shell.)
This is e.g. used in tests/dd/ascii.sh to get all bytes from 0..255
as ASCII characters.
Have a nice day,
Berny