Discussion:
[ast-developers] Configure AST od to print one byte as single hex number per line?
Wendy Lin
2015-01-21 19:16:25 UTC
Permalink
Can I configure AST od to print one byte from stdin as single, 2 digit
hex number, without any file position information? If so, how?
Has anyone found a solution?

Wendy
David Korn
2015-01-27 21:42:13 UTC
Permalink
Can't you do

od -tx1 -An < file | tr ' ' $'\n'

to write one hex byte for each character in file?
Post by Wendy Lin
Can I configure AST od to print one byte from stdin as single, 2 digit
hex number, without any file position information? If so, how?
Has anyone found a solution?
Wendy
_______________________________________________
ast-developers mailing list
http://lists.research.att.com/mailman/listinfo/ast-developers
Danny Weldon
2015-01-28 12:58:26 UTC
Permalink
And here's how to do it in pure shell:

typeset -b c

while read -n 1 c; do printf "%02X\n" "'$(print -v c)'"; done < file
Post by David Korn
Can't you do
od -tx1 -An < file | tr ' ' $'\n'
to write one hex byte for each character in file?
Post by Wendy Lin
Can I configure AST od to print one byte from stdin as single, 2 digit
hex number, without any file position information? If so, how?
Has anyone found a solution?
Wendy
_______________________________________________
ast-developers mailing list
http://lists.research.att.com/mailman/listinfo/ast-developers
_______________________________________________
ast-developers mailing list
http://lists.research.att.com/mailman/listinfo/ast-developers
--
Regards

Danny
phi
2015-01-28 15:35:07 UTC
Permalink
Post by Danny Weldon
typeset -b c
while read -n 1 c; do printf "%02X\n" "'$(print -v c)'"; done < file
And in pure ksh93

CX48$ while read -N 1 c ; do printf '%02x\n' $(('$c')) ; done <yo
48
69
20
54
68
65
72
65
21
0a
phi
2015-01-28 15:46:58 UTC
Permalink
Post by phi
CX48$ while read -N 1 c ; do printf '%02x\n' $(('$c')) ; done <yo
Ha shorter :)


CX48$ while read -N 1 c ; do printf '%02x\n' "'$c'" ; done <yo
48
69
20
54
68
65
72
65
21
0a
phi
2015-01-28 16:01:09 UTC
Permalink
Post by phi
Ha shorter :)
CX48$ while read -N 1 c ; do printf '%02x\n' "'$c'" ; done <yo
48
69
20
54
68
65
72
65
21
0a
Not shorter but easthetical :) No printf formating evalutation, if the 2 digit
output is not fatal.



CX48$ typeset -i 16 x
CX48$ while read -N 1 c ; do x="'$c'" && echo ${x#*#}; done <yo
48
69
20
54
68
65
72
65
21
a

Loading...