How to print ASCII value of a character using basic awk only

前端 未结 3 852
温柔的废话
温柔的废话 2020-12-09 10:09

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)         


        
3条回答
  •  悲&欢浪女
    2020-12-09 11:08

    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
    

提交回复
热议问题