From: Ed Morton on 28 Jan 2010 13:04 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 29 Jan 2010 08:16 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 29 Jan 2010 21:06 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 :-)
First
|
Prev
|
Pages: 1 2 Prev: Bash equivalent of cmd /k switch Next: is there a GNU Coreutils-like toolset for binary files? |