Printing decimal to ascii character, my command does not output as intended
You can't directly print the ascii codes by using the printf "%c" $i
like in C.
You have to first convert the decimal value of i into its octal value and then you have to print it using using printf
and putting \
in front of their respective octal values.
To print A
, you have to convert the decimal 65 into octal, i.e. 101, and then you have to print that octal value as:
printf "\101\n"
This will print A
.
So you have to modify it to :
for i in `seq 32 127`; do printf \\$(printf "%o" $i);done;
But by using awk
you can directly print like in C language
awk 'BEGIN{for(i=32;i<=127;i++)printf "%c",i}';echo
%c
Interprets the associated argument as char: only the first character of a given argument is printed
You seem to already have a way to print them, but here is one variant.
for i in `seq 32 127`; do printf "\x$(printf "%x" $i) $i"; done