(@转载请注明出处:http://blog.youkuaiyun.com/cmatch)
有时候需要在awk中使用位运算,来解决有些字段的解析、判断。但是一般的awk不支持此类运算,幸运的是gawk中可以支持此类运算。下面是手册中的说明:
Bit Manipulations Functions
Starting with version 3.1 of gawk, the following bit manipulation func-
tions are available. They work by converting double-precision floating
point values to unsigned long integers, doing the operation, and then
converting the result back to floating point. The functions are:
and(v1, v2) Return the bitwise AND of the values provided by v1
and v2.
compl(val) Return the bitwise complement of val.
lshift(val, count) Return the value of val, shifted left by count
bits.
or(v1, v2) Return the bitwise OR of the values provided by v1
and v2.
rshift(val, count) Return the value of val, shifted right by count
bits.
xor(v1, v2) Return the bitwise XOR of the values provided by v1
and v2.
举例:
awk '$2=="A" && $3=="P" && and($4,0x00001)==1' /tmp/adzone.xml > tmp
本文介绍了如何在gawk中使用位运算,包括按位与、或、异或等操作,并提供了具体的函数说明及示例代码。
222

被折叠的 条评论
为什么被折叠?



