gawk中使用位运算和用例

本文介绍了如何在gawk中使用位运算,包括按位与、或、异或等操作,并提供了具体的函数说明及示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(@转载请注明出处: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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值