From: Ed Morton on
On Jan 28, 11:23 am, Ed Morton <mortons...(a)gmail.com> wrote:
> On Jan 28, 8:46 am, moonhkt <moon...(a)gmail.com> wrote:
>
> > Hi All
>
> > How to dump the corresponding Hex value for each character using od or
> > other unix command ? Print original character and the hex value.
>
> > Data as below
>
> > A
> > B
> > C
> > 1
> > 2
> > 3
>
> $ cat file
> A
> B
> C
> 1
> 2
> 3
>
> $ gawk '{print $0,strtonum("0x"$0)}' file
> A 10
> B 11
> C 12
> 1 1
> 2 2
> 3 3
>
> $ gawk --non-decimal-data '{printf "%s %d\n",$0,"0x"$0}' file
> A 10
> B 11
> C 12
> 1 1
> 2 2
> 3 3
>
> $ while read c; do printf "%s %d\n" "$c" "0x$c"; done < file
> A 10
> B 11
> C 12
> 1 1
> 2 2
> 3 3
>
> Note that both --non-decimal-data and strtonum() are GNU awk
> extensions and that final example was in bash.
>
>     Ed.

or, if you don't have gnu awk, then:

$ awk '{print $0,index("123456789ABCDEF",$0)}' file
A 10
B 11
C 12
1 1
2 2
3 3

with obvious caveats...

Ed.
From: Geoff Clare on
moonhkt wrote:

> How to dump the corresponding Hex value for each character using od or
> other unix command ? Print original character and the hex value.
>
> Data as below
>
> A
> B
> C
> 1
> 2
> 3

while IFS= read -r c
do printf '%c %x\n' "$c" "'$c"
done

--
Geoff Clare <netnews(a)gclare.org.uk>

From: Maxwell Lol on
moonhkt <moonhkt(a)gmail.com> writes:

> Hi All
>
> How to dump the corresponding Hex value for each character using od or
> other unix command ? Print original character and the hex value.
>
> Data as below
>
> A
> B
> C
> 1
> 2
> 3

I usually use
man ascii
:-)