Ord functions are not provided directly in awk, so when you convert a character to a code, you need to implement it yourself
Copy Code code as follows:
awk ' begin{for (i = 0; i < 256 ++i) {ord[sprintf ("%c", i)] = i;}} ' ' {print ord[' a ']; Ord [' B ']; }'
This mainly constructs the data structure of the Ord for Key,val, the key is Char character, and Val corresponds to the ASCII code
With: awk to get the letter of the ASC value implementation
Copy Code code as follows:
-(Dearvoid@linuxeden:forum)-(~/tmp)-
[$$=18347 $?=0]; Cat Foo.awk
#!/bin/awk-f
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