免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: onion
打印 上一主题 下一主题

请教如何把多行合并成一行。 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2010-02-04 20:44 |只看该作者
明白了 之前都以为awk命令处理方式是 0之后的command都不执行 原来是后面有1还是执行的……

论坛徽章:
0
12 [报告]
发表于 2010-02-04 21:08 |只看该作者
回复 11# nigelrax


    next后awk就跳到下一条记录进行处理了,next后的命令都不执行

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
13 [报告]
发表于 2010-02-04 21:58 |只看该作者
本帖最后由 blackold 于 2010-02-04 23:53 编辑

sed:
  1. sed '/^Include/{:n;N;/\n$/!bn};s/\n//g' urfile
复制代码
awk:
  1. awk '/^Include/,/^$/{if(/^$/) print;else printf $0;next}1' urfile
复制代码

论坛徽章:
0
14 [报告]
发表于 2010-02-05 09:14 |只看该作者
回复 8# ywlscpl
执行后没有变化哦

论坛徽章:
0
15 [报告]
发表于 2010-02-05 09:19 |只看该作者
[b]回复 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=11819417&ptid=1662425]13#[/url] [i]blackold[/i] [/b]


# awk '/^Include/,/^$/{if(/^$/) print;else printf $0;next}1' bb
Policy Name:       test1

  Policy Type:         Standard
  Active:              yes
  Effective date:      01/09/2010 11:44:10
  Client Compress:     no
  Follow NFS Mounts:   no
  Cross Mount Points:  yes
  Collect TIR info:    no
  Block Incremental:   no
  Mult. Data Streams:  no
  Client Encrypt:      no
  Checkpoint:          no
  Policy Priority:     0
  Max Jobs/Policy:     Unlimited
  Disaster Recovery:   0
  Collect BMR info:    no
  Residence:           test1-LTO2
  Volume Pool:         VTL-DB
  Server Group:        *ANY*
  Keyword:             (none specified)
  Data Classification:       -
  Residence is Storage Lifecycle Policy:    no

Granular Restore Info:  no
  HW/OS/Client:  RS6000        AIX5          test1

  Include:  /home/ap
            /home/db
           /home/test

  Schedule:          test1-1d
    Type:            Full Backup
    Maximum MPX:     1
    Synthetic:       0
    PFI Recovery:    0

Policy Name:       test2

  Policy Type:         Standard
  Active:              yes
  Effective date:      01/09/2010 11:44:10
  Client Compress:     no
  Follow NFS Mounts:   no
  Cross Mount Points:  yes
  Collect TIR info:    no
  Block Incremental:   no
  Mult. Data Streams:  no
  Client Encrypt:      no
  Checkpoint:          no
  Policy Priority:     0
  Max Jobs/Policy:     Unlimited
  Disaster Recovery:   0
  Collect BMR info:    no
  Residence:           test2-LTO2
  Volume Pool:         test2-AP
  Server Group:        *ANY*
  Keyword:             (none specified)
  Data Classification:       -
  Residence is Storage Lifecycle Policy:    no

Granular Restore Info:  no
  HW/OS/Client:  RS6000        AIX5          test2

  Include:  /home/out

  Schedule:          test2-1w

还是没变

论坛徽章:
0
16 [报告]
发表于 2010-02-05 09:53 |只看该作者
回复 14# onion


    Include前有空格,自己把语句稍改改吧

论坛徽章:
0
17 [报告]
发表于 2010-02-05 10:00 |只看该作者
看我的超级笨办法,呵呵,见笑哈。

awk '{if($1~/include/){ORS=" ";print $0;}else if($1~/^\//){ORS=" ";print $0;}else{print "\n";ORS="\n";print $0}}'  filename | sed '/^$/d'

论坛徽章:
0
18 [报告]
发表于 2010-02-05 11:11 |只看该作者
回复 16# ywlscpl


    明白,非常感谢

论坛徽章:
0
19 [报告]
发表于 2010-02-05 14:03 |只看该作者
回复 17# youcz


   很好用,谢谢

论坛徽章:
0
20 [报告]
发表于 2010-02-05 23:24 |只看该作者
  1. #!/bin/awk -f
  2.   BEGIN{FS="\n";
  3.         RS="";
  4.        }
  5.    
  6.   {if($1~/Include/){
  7.       for(i=1;i<=NF;i++){
  8.        subscript=split($i,array,"[ ][ ]*");
  9.        for(j=1;j<=subscript;j++)
  10.          printf("%s ",array[j]);
  11.        }
  12.          printf("\n");
  13.      }
  14.   }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP