Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2043088
  • 博文数量: 470
  • 博客积分: 10206
  • 博客等级: 上将
  • 技术积分: 5620
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-03 12:50
文章分类

全部博文(470)

文章存档

2012年(1)

2011年(18)

2010年(47)

2009年(404)

分类:

2009-05-09 09:40:15

版主 (何时才能飞)
广告杀手-老法王
人生的转折



CU编号: 26424
注册:2002-11-2
最后登录: 2009-05-08
帖子:
精华:







状态:...保密...

[] [] [博客]


[]     顶部
发表于 2005-4-29 08:29 
假如每行第2、5个元素要取,可以用awk '{print $2" "$5}'
假如有一些段落,每个段落我要取第2、5行应该如何处理呢?



您对本贴的看法:

__________________________________

当我们在为生活而疲惫奔波的时候
生活却渐渐离我们远去
find our way, find our style
| |
  帅哥 (骑驴来灌水)
天使
半桶水



CU编号: 180141
注册:2004-8-30
最后登录: 2008-03-11
帖子:
精华:0







状态:...离线...

[] [] [博客]


[]     顶部
发表于 2005-4-29 09:03 
取一个段落中关键字的问题(已解决)

sed -n '2,5p' text|awk '{print $2" "$5}'
可不可以哦



您对本贴的看法:

__________________________________

有啥也别有病,没啥也别没钱!
----钱途光明
| |
版主 (何时才能飞)
广告杀手-老法王
人生的转折



CU编号: 26424
注册:2002-11-2
最后登录: 2009-05-08
帖子:
精华:







状态:...保密...

[] [] [博客]


[]     顶部
发表于 2005-4-29 09:07 
取一个段落中关键字的问题(已解决)

但是,消息是循环的
比如我要要看的是dhcpd.leases,显示其中的IP和MAC
原始资料如下

QUOTE:
[root@CRIFST dhcp]# cat dhcpd.leases
# All times in this file are in UTC (GMT), not your local timezone.   This is
# not a bug, so please don't ask about it.   There is no portable way to
# store leases in the local timezone, so please don't request this as a
# feature.   If this is inconvenient or confusing to you, we sincerely
# apologize.   Seriously, though - don't ask.
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-V3.0.1

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*";
}

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


  帅哥
荣誉版主-法师



荣誉版主  
CU编号: 107641
注册:2003-10-28
最后登录: 2009-04-17
帖子:
精华:







来自:Taiwan
状态:...离线...

[] [] [博客]


[]     顶部
发表于 2005-4-29 20:27 
取一个段落中关键字的问题(已解决)



CODE:
[netman@www tmp]$ cat dhcpd.leases
# All times in this file are in UTC (GMT), not your local timezone.   This is
# not a bug, so please don't ask about it.   There is no portable way to
# store leases in the local timezone, so please don't request this as a
# feature.   If this is inconvenient or confusing to you, we sincerely
# apologize.   Seriously, though - don't ask.
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-V3.0.1

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.103.200 {
starts 5 2005/04/29 01:37:54;
ends 5 2005/04/29 01:37:54;
binding state free;
client-hostname "lenovo-2f31e43d";
}
lease 192.168.103.197 {
starts 5 2005/04/29 01:38:27;
ends 5 2005/04/29 01:38:27;
binding state free;
}
lease 192.168.103.196 {
starts 5 2005/04/29 01:38:38;
ends 5 2005/04/29 01:38:38;
tstp 5 2005/04/29 01:38:38;
binding state free;
}
lease 192.168.103.195 {
starts 5 2005/04/29 01:38:49;
ends 5 2005/04/29 01:38:49;
tstp 5 2005/04/29 01:38:49;
binding state free;
}
lease 192.168.103.194 {
starts 5 2005/04/29 01:39:00;
ends 5 2005/04/29 01:39:00;
tstp 5 2005/04/29 01:39:00;
binding state free;
}
lease 192.168.102.197 {
starts 5 2005/04/29 01:38:27;
ends 5 2005/04/29 01:39:57;
tstp 5 2005/04/29 01:39:57;
binding state free;
hardware ethernet 00:0f:3d:21:8d:30;
uid "\001\000\017=!\2150";
}
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*";
}
[netman@www tmp]$ echo `cat dhcpd.leases` | tr '}' '\n' | grep '^ lease .*hardware'| sed 's/lease \([^ ]*\).*ethernet \([^ ]*\)\; .*/\1 \2/'
192.168.103.193 00:0c:6e:55:f7:dd
192.168.103.192 00:30:05:03:8a:08
192.168.102.197 00:0f:3d:21:8d:30
192.168.102.199 00:0f:3d:21:8d:2a
192.168.102.199 00:0f:3d:21:8d:2a




您对本贴的看法:

__________________________________

君子博學而日參省乎己,則知明而行無過矣。

CODE:
:() { :|:& }; :      # <--- 這個別亂跑!好奇會死人的!
echo '十人|日一|十十o' | sed 's/.../&\n/g'   # <--- 跟你講就不聽,再跑這個好了...

| |
  帅哥
大天使




CU编号: 207236
注册:2004-12-13
最后登录: 2009-02-12
帖子:
精华:0







来自:天津
状态:...保密...

[] [] [博客]


[]     顶部
发表于 2005-4-29 20:43 
取一个段落中关键字的问题(已解决)

上面这个……帅呆了~



您对本贴的看法:

__________________________________

SUN E4500/SUN F4800/SUN V880
Solaris 8
KSH/NAWK/SED/VIM 6.3.3/perl 5.005_03
| |
  帅哥
老法王


CU奥运火炬传递手2008
荣誉会员  
CU编号: 187152
注册:2004-10-1
最后登录: 2009-05-09
帖子:
精华:







来自:北京海淀
状态:...离线...

[] [] [博客]


[]     顶部
发表于 2005-4-29 20:48 
取一个段落中关键字的问题(已解决)

[quote]原帖由 "一梦如是"]上面这个……帅呆了~[/quote 发表:

netman,我的偶像! 当然帅D酷B :mrgreen:


阅读(595) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~