免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123456
最近访问板块 发新帖
楼主: platinum

取一个段落中关键字的问题(已解决) [复制链接]

论坛徽章:
0
发表于 2009-08-18 14:16 |显示全部楼层
原帖由 platinum 于 2005-4-29 09:07 发表
但是,消息是循环的
比如我要要看的是dhcpd.leases,显示其中的IP和MAC
原始资料如下

只显示每段的 lease 和 hardware 那两行中的IP和MAC,并合并为一行输出



[root@test~]# more test
lease 192.168.103.198 {
  starts 5 2005/04/29 00:55:41;
  ends 2 2038/01/19 03:14:06;
  tstp 2 2038/01/19 03:14:06;
  binding state active;
  next binding state free;
  hardware ethernet 00:30:05:06:af:14;
  uid "\001\0000\005\006\257\024";
  client-hostname "secend";
}
lease 192.168.103.193 {
  starts 5 2005/04/29 00:58:07;
  ends 2 2038/01/19 03:14:06;
  tstp 2 2038/01/19 03:14:06;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:6e:55:f7:dd;
  uid "\001\000\014nU\367\335";
  client-hostname "gaohangjun";
}
lease 192.168.103.192 {
  starts 5 2005/04/29 00:59:00;
  ends 2 2038/01/19 03:14:06;
  binding state active;
  next binding state free;
  hardware ethernet 00:30:05:03:8a:08;
  uid "\001\0000\005\003\212\010";
  client-hostname "jj";
}
lease 192.168.102.199 {
  starts 5 2005/04/29 00:59:46;
  ends 2 2038/01/19 03:14:06;
  binding state active;
  next binding state free;
  hardware ethernet 00:0f:3d:21:8d:2a;
  uid "\001\000\017=!\215*";
  client-hostname "DLA502";
}
lease 192.168.102.199 {
  starts 5 2005/04/29 00:59:46;
  ends 5 2005/04/29 01:01:16;
  tstp 5 2005/04/29 01:01:16;
  binding state free;
  hardware ethernet 00:0f:3d:21:8d:2a;
  uid "\001\000\017=!\215*";
}
[root@test ~]#


[root@test ~]# awk '/lease|hardware/' test | sed 's/{//g' | awk '{print $NF}' | sed -n 'N;s/\n/\t\t/p'
192.168.103.198         00:30:05:06:af:14;
192.168.103.193         00:0c:6e:55:f7:dd;
192.168.103.192         00:30:05:03:8a:08;
192.168.102.199         00:0f:3d:21:8d:2a;
192.168.102.199         00:0f:3d:21:8d:2a;

[ 本帖最后由 小木虫子 于 2009-8-18 14:17 编辑 ]

论坛徽章:
0
发表于 2010-03-02 16:50 |显示全部楼层
awk '{if($0~/^lease/)printf "%s\t",$2;if($0~/hard/)print $3}'

论坛徽章:
0
发表于 2010-03-02 17:13 |显示全部楼层

  1. sed -n '/^lease/{s/lease //;s/ {//;p;:a;n;/hardware/!ba;s/  hardware ethernet //;s/;//;p}'
复制代码

论坛徽章:
0
发表于 2010-03-02 17:52 |显示全部楼层
perl 如何解决?

论坛徽章:
0
发表于 2010-08-10 14:47 |显示全部楼层
  1. # grep -E '(lease)|(hardware)' lease.txt | sed -e '$!N; s/\n/ /; s/;$//' | awk '{ print $2" "$6 }'
  2. 192.168.103.198 00:30:05:06:af:14
  3. 192.168.103.193 00:0c:6e:55:f7:dd
  4. 192.168.103.192 00:30:05:03:8a:08
  5. 192.168.102.199 00:0f:3d:21:8d:2a
  6. 192.168.102.199 00:0f:3d:21:8d:2a
复制代码

论坛徽章:
0
发表于 2014-10-21 14:52 |显示全部楼层
awk '/lease/{printf $2" "}/hardware/{print $3}' filename
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP