I need to print the ASCII value of the given charecter in awk only.
the below gives 0 as output.
echo a | awk '{ printf("%d \n",$1); }'
Help please.
I need to print the ASCII value of the given charecter in awk only.
the below gives 0 as output.
echo a | awk '{ printf("%d \n",$1); }'
Help please.
It seems this is not a trivial problem. I found this approach using a lookup array, which should work for A-Z at least:
BEGIN { convert="ABCDEFGHIJKLMNOPQRSTUVWXYZ" }
{ num=index(convert,substr($0,2,1))+64; print num }
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?
$ printf "%d" "'a"
97