Chinaunix首页 | 论坛 | 博客
  • 博客访问: 166248
  • 博文数量: 21
  • 博客积分: 2371
  • 博客等级: 大尉
  • 技术积分: 217
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-15 18:36
文章分类

全部博文(21)

文章存档

2010年(6)

2009年(15)

分类:

2009-03-31 15:36:15

数据文件file

15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
1:2,2:3,3:4,5:7,78:89,45:65,555:897,895:23232,5666:5654
1,2:3,454,45:656,78:656,56,7878:66565,5454:9787,34,56,8989:3242
1,2:3,454,45:656,78:656,56,7878:66565,5454:9787,17,3242:343434,15
1:2,3:4,4:5,6:7,8:9,10:11,12:13,14:45,45:56
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16

处理后一行端口数最多15个,78:89算占用2个端口,78:89形式的不能拆开

awk -F "," '{for (i=1;i<=NF;i++) {c++;if ($i~/:/) c++;if ((c-1)%15!=0) printf $i",";if (c%15==0) {print "";c=0}if ((c+1)%15==0) if ($i~/:/) {print "";c=0}if ((c-1)%15==0) if ($i~/:/) {printf "\n"$i",";c=0}else printf $i","}print "";c=0}' file | sed 's/\,$//'

处理后

15,16,17,18,19,20,21,22,23,24,25,26,27,28,29
30
1:2,2:3,3:4,5:7,78:89,45:65,555:897
895:23232,5666:5654
1,2:3,454,45:656,78:656,56,7878:66565,5454:9787,34,56
8989:3242
1,2:3,454,45:656,78:656,56,7878:66565,5454:9787,17
3242:343434,15
1:2,3:4,4:5,6:7,8:9,10:11,12:13
14:45,45:56
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
16

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