QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1150|回复: 4

awk方法疑惑!请指点!!

[复制链接]
发表于 2005-9-13 16:12:30 | 显示全部楼层 |阅读模式
我现在一个问题,不知大家有没有注意,我的icmp_seq是不连续的,如下
代码:
[code:1]
64 bytes from 192.168.100.40: icmp_seq=1 ttl=64 time=0.043 ms
64 bytes from 192.168.100.40: icmp_seq=2 ttl=64 time=0.033 ms
64 bytes from 192.168.100.40: icmp_seq=3 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=5 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=6 ttl=64 time=0.032 ms
64 bytes from 192.168.100.40: icmp_seq=7 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=9 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=10 ttl=64 time=0.038 ms
64 bytes from 192.168.100.40: icmp_seq=11 ttl=64 time=0.038 ms
64 bytes from 192.168.100.40: icmp_seq=12 ttl=64 time=0.028 ms
[/code:1]
我现在想在icmp_seq=3这行与icmp_seq=5 中间加上一行 request timeout,在icmp_seq=7这行与icmp_seq=9 中间加上一行 request timeout然后仍然以4行一组输出,如下:
代码:
[code:1]
64 bytes from 192.168.100.40: icmp_seq=1 ttl=64 time=0.043 ms
64 bytes from 192.168.100.40: icmp_seq=2 ttl=64 time=0.033 ms
64 bytes from 192.168.100.40: icmp_seq=3 ttl=64 time=0.034 ms
request timeout

64 bytes from 192.168.100.40: icmp_seq=5 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=6 ttl=64 time=0.032 ms
64 bytes from 192.168.100.40: icmp_seq=7 ttl=64 time=0.034 ms
request timeout

64 bytes from 192.168.100.40: icmp_seq=9 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=10 ttl=64 time=0.038 ms
64 bytes from 192.168.100.40: icmp_seq=11 ttl=64 time=0.038 ms
64 bytes from 192.168.100.40: icmp_seq=12 ttl=64 time=0.028 ms
[/code:1]

再扩展一下,icmp_seq是顺序显示的,我的目的就是将icmp_seq这个值没有出来的行用request timeout来替代.而且四行一组,的表示出来.!请高手帮忙.(注:上面ping值不是全部,而只是一小部分),如下:
代码:
[code:1]
64 bytes from 192.168.100.40: icmp_seq=1 ttl=64 time=0.043 ms
64 bytes from 192.168.100.40: icmp_seq=2 ttl=64 time=0.033 ms
64 bytes from 192.168.100.40: icmp_seq=3 ttl=64 time=0.034 ms
request timeout

64 bytes from 192.168.100.40: icmp_seq=5 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=6 ttl=64 time=0.032 ms
64 bytes from 192.168.100.40: icmp_seq=7 ttl=64 time=0.034 ms
request timeout

64 bytes from 192.168.100.40: icmp_seq=9 ttl=64 time=0.034 ms
64 bytes from 192.168.100.40: icmp_seq=10 ttl=64 time=0.038 ms
64 bytes from 192.168.100.40: icmp_seq=11 ttl=64 time=0.038 ms
64 bytes from 192.168.100.40: icmp_seq=12 ttl=64 time=0.028 ms

request timeout
request timeout
64 bytes from 192.168.100.40: icmp_seq=15 ttl=64 time=0.038 ms
64 bytes from 192.168.100.40: icmp_seq=16 ttl=64 time=0.028 ms

...
[/code:1]
请高手帮忙!!
发表于 2005-9-14 22:05:54 | 显示全部楼层
只用单条命令我是搞不定,用shell脚本。不知道是否符合你大要求
回复

使用道具 举报

发表于 2005-9-21 23:49:10 | 显示全部楼层
[code:1]awk -F"=" 'BEGIN{i=1}{split($2,a," ");for(;i<a[1];){print "request timeout\n";i++}{print;i++}}'
[/code:1]
回复

使用道具 举报

发表于 2005-9-22 00:33:26 | 显示全部楼层
^_^还是要几个命令,有谁能用一句话搞定?
回复

使用道具 举报

发表于 2005-10-20 00:16:18 | 显示全部楼层
[code:1]sed -e '{
/icmp_seq=3/a\
request timeout
/icmp_seq=7/a\
request timeout
}'[/code:1]
大概就是这样的,可能具体的语法有点小问题。
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-11-2 16:40 , Processed in 0.051617 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表