- 论坛徽章:
- 0
|
[quote]原帖由 awk就是awp加ak 于 2006-10-23 17:46 发表
当我欠你的了。。试一下这个,不行再说- awk -F'[. -]' '
- {
- counts = 1;
- for (i = 3; i >= 0; i--){
- counts1[i] = $(NF-i);
- counts2[i] = $(4-i);
- }
- for (i = 0; i < 4; i++) if (c ... [/quote]
- [code]
- 谢谢你热心的帮助
- 运行结果如下:
- [root@root test]# cat a
- 060.166.000.000 060.166.255.255
- 060.167.000.000 060.167.127.255
- 060.167.128.000 060.169.255.255
- 060.170.000.000 060.170.127.255
- 060.170.128.000 060.170.255.255
- 060.171.000.000 060.171.063.255
复制代码
- [root@root test]# cat test.sh
- #!/bin/bash
- awk -F'[. -]' '
- {
- counts = 1;
- for (i = 3; i >= 0; i--){
- counts1[i] = $(NF-i);
- counts2[i] = $(4-i);
- }
- for (i = 0; i < 4; i++) if (counts1[i] < counts2[i]){ counts1[i+1]--; counts1[i] += 256; }
- for (i = 0; i < 4; i++) counts *= (counts1[i] - counts2[i] + 1);
- print $1"."$2"."$3"."$4, counts;
- }' a
复制代码
- [root@root test]# sh test.sh
- 060.166.000.000 1160570880
- 060.167.000.000 1147675648
- 060.167.128.000 573837824
- 060.170.000.000 1108989952
- 060.170.128.000 554494976
- 060.171.000.000 1096094720
复制代码
ip数太夸张了吧? 呵呵 上亿? a文件的这些ip段只是国内安徽省的ip
是不是我那里出错了么?
[ 本帖最后由 frankzh 于 2006-10-23 18:48 编辑 ] |
|