我有两个输入文件:
cat 2OCS_VOICECALLS_1111_11_111111
111111111 902123124 201605240534270000000070OCS0144 01.0946 0.3729
111111111 902123125 201605222207410000000070OCS8182 00.8980 0.1
111111111 902123126 201605222319190000000015OCS1573 6.3854 6.11
111111111 902123126 201605230752420000000080OCS1223 00.8002 0.0
111111111 902123123 201605231525320000000073OCS1394 01.2194 0.4
111111111 902123123 201605231708080000000570OCS1040 011.1977 6.3
111111111 350 201605240042070000000236OCS4252 3.6344 1.55
111111111 1 201605240114430000000123OCS1154 03.0537 1.89
111111111 3 201605240246070000000009OCS0707 018.6965 18.4
111111111 423 201605240530500000000213OCS0130 01.8881 0.00
111111111 5 201605240530500000000213OCS0130 01.8881 0.00
111111111 470 201605240601120000000015OCS0156 015.8059 15.5
111111111 600 201605240601120000000015OCS0156 015.8059 15.5
111111111 400 201605240601120000000015OCS0156 015.8059 15.5
另一个档案
cat BlackList_B_Number.dat
902123123 902123125
902123127 902123128
450 600
1 400
我希望匹配超出数字范围并在不同文件的范围内。我试过这个:
awk -v FILE1="FILE1.out" -v FILE2="FILE2.out" 'NR==FNR{for (i=$1; i<=$2; i++) wanted[i] ;next}($2 in wanted){print > FILE1}!($2 in wanted){print > FILE2}' BlackList_B_Number.dat 2OCS_VOICECALLS_1111_11_111111
但是我没有得到预期的输出,因为902123124
应该在FILE1
中,而不在FILE2
中:
cat FILE1.out
111111111 902123123 201605231525320000000073OCS1394 01.2194 0.4
111111111 902123123 201605231708080000000570OCS1040 011.1977 6.3
111111111 350 201605240042070000000236OCS4252 3.6344 1.55
111111111 1 201605240114430000000123OCS1154 03.0537 1.89
111111111 3 201605240246070000000009OCS0707 018.6965 18.4
111111111 5 201605240530500000000213OCS0130 01.8881 0.00
111111111 470 201605240601120000000015OCS0156 015.8059 15.5
111111111 600 201605240601120000000015OCS0156 015.8059 15.5
111111111 400 201605240601120000000015OCS0156 015.8059 15.5
cat FILE2.out
111111111 902123124 201605240534270000000070OCS0144 01.0946 0.3729
111111111 902123125 201605222207410000000070OCS8182 00.8980 0.1
111111111 902123126 201605222319190000000015OCS1573 6.3854 6.11
111111111 902123126 201605230752420000000080OCS1223 00.8002 0.0
111111111 423 201605240530500000000213OCS0130 01.8881 0.00
答案 0 :(得分:0)
awk -v FILE1="FILE1.out" -v FILE2="FILE2.out" '
FNR==NR {BLs[++BSize]=$1;BHs[BSize]=$2;next}
{
Blacked=0
for( i=1; i<BSize && ! Blacked; i++) Blacked = ( $2 >= BLs[i] && $2 <= BHs[i])
#print "DEBUG:: " FNR ": Blacked: " Blacked " : " $0
if ( Blacked ) print > FILE2
else print > FILE1
}' BlackList_B_Number.dat 2OCS_VOICECALLS_1111_11_111111
您没有检查版本中2值之间的值,但如果列出的值的一部分(您在之间指定,我假设边缘包含在之间)
说明: - 通过读取第一个文件(黑名单)加载2个数组以进行限制规范,1表示低,1表示高 - 阅读下一个文件(数据) - 如果数字在每个指定的限制之间(如果有的话,在第一次停止时停止)并且定义是否变黑,则在每一行上进行比较 - 取决于Balcked状态,打印到文件1或2