免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2917 | 回复: 7

请教下如何使用shell排序dhcpd.conf中绑定的IP [复制链接]

论坛徽章:
0
发表于 2011-04-19 17:16 |显示全部楼层
请教怎样写才能根据fixed-address后面的ip地址进行排序下呢?
例如:
  1. host D8PDD002
  2.        {
  3.   hardware ethernet 00:E0:4C:22:AC:95;
  4.   fixed-address 10.0.42.203;
  5.        }

  6. host D8PDD001
  7.        {
  8.   hardware ethernet 00:40:05:43:06:5F;
  9.   fixed-address 10.0.42.113;
  10.        }

  11. host D8PDD003
  12.        {
  13.   hardware ethernet 00:E0:4C:30:EA:44;
  14.   fixed-address 10.0.42.100;
  15.        }

  16. host D8PDD004
  17.        {
  18.   hardware ethernet 00:E0:4C:60:8C:9D;
  19.   fixed-address 10.0.42.101;
  20.        }

  21. host D8JJD001
  22.        {
  23.   hardware ethernet 00:14:78:57:35:27;
  24.   fixed-address 10.0.42.177;
  25.        }

  26. host D8JJD002
  27.        {
  28.   hardware ethernet 00:15:f2:a0:1f:bb;
  29.   fixed-address 10.0.42.178;
  30.        }
复制代码

论坛徽章:
0
发表于 2011-04-19 17:44 |显示全部楼层
本帖最后由 只爱睡觉 于 2011-04-19 17:53 编辑

抛砖引玉
cat 5.txt | awk '{print $2}' | grep -E '[\d+\.\d+\.\d+\.\d+]' | sort | uniq

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2011-04-19 17:48 |显示全部楼层
本帖最后由 greysky-zfj 于 2011-04-19 17:49 编辑

grep -E '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' file|awk '{print $2}'|sort -k4n

论坛徽章:
0
发表于 2011-04-19 18:03 |显示全部楼层
回复 1# lbt5210


    这个意思?
  1. ywlscpl@ubuntu:~$ awk '{v=v"\n"$0}/fixed/{ip=$2}/}/{a[ip]=v;v=""}END{n=asorti(a,b);for (i=1;i<=n;i++) print a[b[i]]}' file


  2. host D8PDD003
  3.        {
  4.   hardware ethernet 00:E0:4C:30:EA:44;
  5.   fixed-address 10.0.42.100;
  6.        }


  7. host D8PDD004
  8.        {
  9.   hardware ethernet 00:E0:4C:60:8C:9D;
  10.   fixed-address 10.0.42.101;
  11.        }


  12. host D8PDD001
  13.        {
  14.   hardware ethernet 00:40:05:43:06:5F;
  15.   fixed-address 10.0.42.113;
  16.        }


  17. host D8JJD001
  18.        {
  19.   hardware ethernet 00:14:78:57:35:27;
  20.   fixed-address 10.0.42.177;
  21.        }


  22. host D8JJD002
  23.        {
  24.   hardware ethernet 00:15:f2:a0:1f:bb;
  25.   fixed-address 10.0.42.178;
  26.        }

  27. host D8PDD002
  28.        {
  29.   hardware ethernet 00:E0:4C:22:AC:95;
  30.   fixed-address 10.0.42.203;
  31.        }
复制代码

评分

参与人数 1可用积分 +2 收起 理由
lbt5210 + 2 非常感谢!

查看全部评分

论坛徽章:
3
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:51:162015年亚洲杯之阿曼
日期:2015-04-07 20:00:59
发表于 2011-04-19 18:05 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
发表于 2011-04-19 20:24 |显示全部楼层
回复 4# ywlscpl

非常感谢大家
就是需要这样的实现。
我试试看看可不可以
感恩!

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
发表于 2011-04-20 02:24 |显示全部楼层
本帖最后由 yinyuemi 于 2011-04-20 02:37 编辑

回复 1# lbt5210
  1. awk 'BEGIN{RS=ORS="\n\n";FS="\n"}{a[$4]=$4;b[$4]=$0}END{x=asort(a);for(i=1;i<=x;i++) print b[a[i]]}' file
复制代码

论坛徽章:
0
发表于 2011-04-20 08:32 |显示全部楼层
回复 7# yinyuemi


    感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP