I need to print the ASCII value of the given character in awk only.
Below code gives 0
as output:
echo a | awk '{ printf("%d \n",$1); }'
I need to print the ASCII value of the given character in awk only.
Below code gives 0
as output:
echo a | awk '{ printf("%d \n",$1); }'
Using only basic awk (not even gawk, so the below should work on all BSD and Linux variants):
Here's the opposite direction (for completeness):
Basic premise is to use a lookup table.
see the awk manual for ordinal functions you can use. But since you are using awk, you should be on some version of shell, eg bash. so why not use the shell?
It seems this is not a trivial problem. I found this approach using a lookup array, which should work for A-Z at least: