coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hex to ASCII conversion?


From: Bob Proulx
Subject: Re: Hex to ASCII conversion?
Date: Wed, 14 Jan 2015 13:10:29 -0700
User-agent: Mutt/1.5.23 (2014-03-12)

Hello LxC,

LxC wrote:
> Bob Proulx wrote on 25 Dec 2014:
> > 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 use a shell alias with perl as "hexer":
> 
> alias hx='perl -ne'\''printf "%*vX\n"," ","$_"'\'
> alias hxr="perl -ne'for(split){print chr hex}'"
> 
> 4058 0 /tmp $ echo 48 61 70 70 79 A | hxr
> Happy
> 
> 4059 0 /tmp $ echo Happy | hx
> 48 61 70 70 79 A

Cool.  Thanks for sharing!

In the end I discovered that printf will do the conversion using
escape expansion.  I was sure there was a way.  I had missed the
printf escape expansion mechanism.

  $ printf "\x48\x61\x70\x70\x79\n"
  Happy

And for the original task (easily decoding a clever traceroute hack)
it is now easy to do:

  $ echo 
48.61.70.70.79.20.48.6f.6c.69.64.61.79.73.20.46.72.65.65.6e.6f.64.65.20.23.63.69.73.63.6f
 | tr . "\n" | while read c; do printf "\x$c";done;echo
  Happy Holidays Freenode #cisco

Fun!

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]