AWK 合并行
博客专区 > jastme 的博客 > 博客详情
AWK 合并行
jastme 发表于4年前
AWK 合并行
  • 发表于 4年前
  • 阅读 162
  • 收藏 1
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

root@Scrapy:/tmp# cat test.txt 
host_name               beijing-192.168.1.104
host_name               beijing-192.168.1.105
host_name               beijing-192.168.1.103
host_name               beijing-192.168.1.250
host_name               beijing-192.168.1.252
host_name               beijing-192.168.1.251
host_name               beijing-192.168.1.122
host_name               beijing-192.168.1.123
host_name               beijing-192.168.1.132
host_name               beijing-192.168.1.133
host_name               beijing-192.168.1.152
host_name               beijing-192.168.1.153
host_name               tianjin-172.168.10.11
host_name               tianjin-172.168.10.12
host_name               tianjin-172.168.10.13
host_name               tianjin-172.168.10.14
host_name               tianjin-172.168.10.15
host_name               tianjin-172.168.10.19
host_name               tianjin-172.168.10.20
host_name               liaoning-172.168.10.11
host_name               liaoning-172.168.10.12
host_name               liaoning-172.168.10.13
host_name               liaoning-172.168.10.14
host_name               liaoning-172.168.10.15
host_name               liaoning-172.168.10.20
host_name               liaoning-172.168.10.21

########################################################################################

root@Scrapy:/tmp# awk -F:' |-' '{print $1}' test.txt            判断下分隔符

host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               beijing
host_name               tianjin
host_name               tianjin
host_name               tianjin
host_name               tianjin
host_name               tianjin
host_name               tianjin
host_name               tianjin
host_name               liaoning
host_name               liaoning
host_name               liaoning
host_name               liaoning
host_name               liaoning
host_name               liaoning
host_name               liaoning

root@Scrapy:/tmp# awk -F:' |-' '{a[$1]=a[$1]" "$2}END{for (i in a)print i,a[i]}' test.txt

host_name               liaoning  172.168.10.11 172.168.10.12 172.168.10.13 172.168.10.14 172.168.10.15 172.168.10.20 172.168.10.21
host_name               tianjin  172.168.10.11 172.168.10.12 172.168.10.13 172.168.10.14 172.168.10.15 172.168.10.19 172.168.10.20
host_name               beijing  192.168.1.104 192.168.1.105 192.168.1.103 192.168.1.250 192.168.1.252 192.168.1.251 192.168.1.122 
                                 192.168.1.123 192.168.1.132 192.168.1.133 192.168.1.152 192.168.1.153


共有 人打赏支持
粉丝 35
博文 122
码字总数 59358
×
jastme
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: