时间:2021-02-22 18:03:01 | 栏目:Shell | 点击:次
在awk中并未直接提供ord函数,所以在将某个字符转换为码时,需要自己来实现
这里主要是构造了ord为key,val的数据结构,key为char字符,val对应的ascii码
附:awk得到字母的ASC值实现
BEGIN {
for (ii = 0; ii < 256; ++ii) {
ch = sprintf("%c", ii);
ascii[ch] = ii;
}
for (ii = 1; ii < ARGC; ii++) {
print "ord(" ARGV[ii] " = " ascii[ARGV[ii]];
}
}
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=18347 $?=0] ; ./foo.awk a b c 1 2 3
ord(a) = 97
ord(b) = 98
ord(c) = 99
ord(1) = 49
ord(2) = 50
ord(3) = 51
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=18347 $?=0] ; bye