求解awk按不同条件采用不同的分隔符
本帖最后由 nugget 于 2011-04-15 23:28 编辑
1、有关键字start的行,按"_"分割输出第1部分;
2、当www开始的行,按" "分割输出第5部分;
希望结果是:
#########DNS:202.106.0.20
us.sina.com.cn.
#########DNS:202.106.0.20
us.sina.com.cn.
求awk的解法,多谢了!
测试提供的数据:
#########DNS:202.106.0.20_start###########
;; QUESTION SECTION:
;www.sina.com. IN A
;; ANSWER SECTION:
www.sina.com. 34 IN CNAME us.sina.com.cn.
us.sina.com.cn. 36 IN CNAME news.sina.com.cn.
news.sina.com.cn. 6 IN CNAME jupiter.sina.com.cn.
jupiter.sina.com.cn. 56 IN CNAME libra.sina.com.cn.
libra.sina.com.cn. 145 IN A 202.108.33.74
libra.sina.com.cn. 145 IN A 202.108.33.75
libra.sina.com.cn. 145 IN A 202.108.33.76
libra.sina.com.cn. 145 IN A 202.108.33.77
libra.sina.com.cn. 145 IN A 202.108.33.78
libra.sina.com.cn. 145 IN A 202.108.33.79
libra.sina.com.cn. 145 IN A 202.108.33.80
libra.sina.com.cn. 145 IN A 202.108.33.81
libra.sina.com.cn. 145 IN A 202.108.33.82
libra.sina.com.cn. 145 IN A 202.108.33.97
libra.sina.com.cn. 145 IN A 202.108.33.98
libra.sina.com.cn. 145 IN A 202.108.33.99
libra.sina.com.cn. 145 IN A 202.108.33.70
libra.sina.com.cn. 145 IN A 202.108.33.71
libra.sina.com.cn. 145 IN A 202.108.33.72
libra.sina.com.cn. 145 IN A 202.108.33.73
;; Query time: 2 msec
;; SERVER: 202.106.0.20#53(202.106.0.20)
;; WHEN: Fri Apr 15 23:20:05 2011
;; MSG SIZE rcvd: 375
#########DNS:202.106.0.20_end###########
#########DNS:202.106.0.20_start###########
;; QUESTION SECTION:
;www.sina.com. IN A
;; ANSWER SECTION:
www.sina.com. 36 IN CNAME us.sina.com.cn.
us.sina.com.cn. 38 IN CNAME news.sina.com.cn.
news.sina.com.cn. 59 IN CNAME jupiter.sina.com.cn.
jupiter.sina.com.cn. 59 IN CNAME libra.sina.com.cn.
libra.sina.com.cn. 407 IN A 202.108.33.75
libra.sina.com.cn. 407 IN A 202.108.33.76
libra.sina.com.cn. 407 IN A 202.108.33.77
libra.sina.com.cn. 407 IN A 202.108.33.91
libra.sina.com.cn. 407 IN A 202.108.33.92
libra.sina.com.cn. 407 IN A 202.108.33.94
libra.sina.com.cn. 407 IN A 202.108.33.95
libra.sina.com.cn. 407 IN A 202.108.33.96
libra.sina.com.cn. 407 IN A 202.108.33.97
libra.sina.com.cn. 407 IN A 202.108.33.98
libra.sina.com.cn. 407 IN A 202.108.33.99
libra.sina.com.cn. 407 IN A 202.108.33.70
libra.sina.com.cn. 407 IN A 202.108.33.71
libra.sina.com.cn. 407 IN A 202.108.33.72
libra.sina.com.cn. 407 IN A 202.108.33.73
libra.sina.com.cn. 407 IN A 202.108.33.74
;; Query time: 2 msec
;; SERVER: 202.106.0.20#53(202.106.0.20)
;; WHEN: Fri Apr 15 23:20:05 2011
;; MSG SIZE rcvd: 375
#########DNS:202.106.0.20_end###########
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也想知道...
逻辑不难,就是不知道awk语法。问题提的不错!请能者说说。
复制代码
回复 1# nugget
复制代码
LS的几位真厉害 !
谢谢!