如何只使用基本的AWK打印字符的ASCII值 [英] How to print ASCII value of a character using basic awk only

查看:156
本文介绍了如何只使用基本的AWK打印字符的ASCII值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打印在awk中的给定字符的ASCII值只。

下面code给出 0 作为输出:

 回声| AWK'{printf的(%d个\\ n,$ 1); }


解决方案

看到的序功能就可以使用。但是,由于您使用的是AWK,你应该对某些版本的外壳,如猛砸。那么为什么不使用shell?

  $ printf的%d的一
97

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); }'

解决方案

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

这篇关于如何只使用基本的AWK打印字符的ASCII值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆