【求助】多行文本格式化为符合条件的行

create unique index "informix".ipreregcn_id on "informix".preregcn
    (id) using btree  in idxdbs ;
create index "informix".ihisdirectproduct_doapst on "informix"
    .hisdirectproduct (domainname,applytype,state) using btree
     in idxdbs ;
create index "informix".ifundgift_us on "informix".fundgift (username)
    using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_ad on "informix"
    .additionalsubproduct (additionalproductid) using btree  
    in datadbs ;
create index "informix".iadditionalsubproduct_do on "informix"
    .additionalsubproduct (domainname) using btree  in idxdbs
    ;
create index "informix".iadditionalsubproduct_id on "informix"
    .additionalsubproduct (id) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_re on "informix"
    .additionalsubproduct (recordid) using btree  in idxdbs ;
   
create index "informix".iadditionalsubproduct_se on "informix"
    .additionalsubproduct (serial) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_us on "informix"
    .additionalsubproduct (username) using btree  in idxdbs ;
   
create index "informix".ilicenseaction_id on "informix".licenseaction
    (id) using btree  in idxdbs ;
create index "informix".iwebtrustactiondomain_do on "informix"
    .webtrustactiondomain (domainname) using btree  in idxdbs
    ;

将以上内容用脚本变为create开头、分号结尾的多行,"informix"    .additionalsubproduct ->,"informix".additionalsubproduct
最后格式如下:
create unique index "informix".ipreregcn_id on "informix".preregcn     (id) using btree  in idxdbs ;
create index "informix".ihisdirectproduct_doapst on "informix".hisdirectproduct (domainname,applytype,state) using btree      in idxdbs ;
create index "informix".ifundgift_us on "informix".fundgift (username)     using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_ad on "informix".additionalsubproduct (additionalproductid) using btree      in datadbs ;
create index "informix".iadditionalsubproduct_do on "informix".additionalsubproduct (domainname) using btree  in idxdbs     ;
create index "informix".iadditionalsubproduct_id on "informix".additionalsubproduct (id) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_re on "informix".additionalsubproduct (recordid) using btree  in idxdbs ;   
create index "informix".iadditionalsubproduct_se on "informix".additionalsubproduct (serial) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_us on "informix".additionalsubproduct (username) using btree  in idxdbs ;
create index "informix".ilicenseaction_id on "informix".licenseaction     (id) using btree  in idxdbs ;
create index "informix".iwebtrustactiondomain_do on "informix".webtrustactiondomain (domainname) using btree  in idxdbs     ;

作者: flyinweb_cu   发布时间: 2011-06-09

本帖最后由 where27 于 2011-06-09 17:31 编辑

awk '/;$/{print;next}{printf $0}' file

作者: where27   发布时间: 2011-06-09



QUOTE:
awk '/;$/{print;next}{printf $0}' file
where27 发表于 2011-06-09 17:29



[informix@smtp shane]$ awk '/;$/{print;next}{printf $0}'  sql.txt
create unique index "informix".ipreregcn_id on "informix".preregcn     (id) using btree  in idxdbs ;
create index "informix".ihisdirectproduct_doapst on "informix"    .hisdirectproduct (domainname,applytype,state) using btree      in idxdbs ;
create index "informix".ifundgift_us on "informix".fundgift (username)     using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_ad on "informix"    .additionalsubproduct (additionalproductid) using btree      in datadbs ;
create index "informix".iadditionalsubproduct_do on "informix"    .additionalsubproduct (domainname) using btree  in idxdbs     ;
create index "informix".iadditionalsubproduct_id on "informix"    .additionalsubproduct (id) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_re on "informix"    .additionalsubproduct (recordid) using btree  in idxdbs ;
    create index "informix".iadditionalsubproduct_se on "informix"    .additionalsubproduct (serial) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_us on "informix"    .additionalsubproduct (username) using btree  in idxdbs ;
    create index "informix".ilicenseaction_id on "informix".licenseaction     (id) using btree  in idxdbs ;
create index "informix".iwebtrustactiondomain_do on "informix"    .webtrustactiondomain (domainname) using btree  in idxdbs     ;

基本可以实现,"informix"    .additionalsubproduct 中间的空格还需要另外再处理

作者: flyinweb_cu   发布时间: 2011-06-09

cat 6|while read i; do a="p`echo $i|grep ";"|cut -c 1`"; if [ $a = p ]; then echo -n $i; else echo $i; fi; done

作者: gooutya1   发布时间: 2011-06-09

# cat 6
create unique index "informix".ipreregcn_id on "informix".preregcn
    (id) using btree  in idxdbs ;
create index "informix".ihisdirectproduct_doapst on "informix"
    .hisdirectproduct (domainname,applytype,state) using btree
     in idxdbs ;
create index "informix".ifundgift_us on "informix".fundgift (username)
    using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_ad on "informix"
    .additionalsubproduct (additionalproductid) using btree  
    in datadbs ;
create index "informix".iadditionalsubproduct_do on "informix"
    .additionalsubproduct (domainname) using btree  in idxdbs
    ;
create index "informix".iadditionalsubproduct_id on "informix"
    .additionalsubproduct (id) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_re on "informix"
    .additionalsubproduct (recordid) using btree  in idxdbs ;
   
create index "informix".iadditionalsubproduct_se on "informix"
    .additionalsubproduct (serial) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_us on "informix"
    .additionalsubproduct (username) using btree  in idxdbs ;
   
create index "informix".ilicenseaction_id on "informix".licenseaction
    (id) using btree  in idxdbs ;
create index "informix".iwebtrustactiondomain_do on "informix"
    .webtrustactiondomain (domainname) using btree  in idxdbs
    ;
# cat 6|while read i; do a="p`echo $i|grep ";"|cut -c 1`"; if [ $a = p ]; then echo -n $i; else echo $i; fi; done
create unique index "informix".ipreregcn_id on "informix".preregcn(id) using btree in idxdbs ;
create index "informix".ihisdirectproduct_doapst on "informix".hisdirectproduct (domainname,applytype,state) using btreein idxdbs ;
create index "informix".ifundgift_us on "informix".fundgift (username)using btree in idxdbs ;
create index "informix".iadditionalsubproduct_ad on "informix".additionalsubproduct (additionalproductid) using btreein datadbs ;
create index "informix".iadditionalsubproduct_do on "informix".additionalsubproduct (domainname) using btree in idxdbs;
create index "informix".iadditionalsubproduct_id on "informix".additionalsubproduct (id) using btree in idxdbs ;
create index "informix".iadditionalsubproduct_re on "informix".additionalsubproduct (recordid) using btree in idxdbs ;
create index "informix".iadditionalsubproduct_se on "informix".additionalsubproduct (serial) using btree in idxdbs ;
create index "informix".iadditionalsubproduct_us on "informix".additionalsubproduct (username) using btree in idxdbs ;
create index "informix".ilicenseaction_id on "informix".licenseaction(id) using btree in idxdbs ;
create index "informix".iwebtrustactiondomain_do on "informix".webtrustactiondomain (domainname) using btree in idxdbs;

作者: gooutya1   发布时间: 2011-06-09



QUOTE:
# cat 6
create unique index "informix".ipreregcn_id on "informix".preregcn
    (id) using btree   ...
gooutya1 发表于 2011-06-09 17:40




    方法可行

作者: flyinweb_cu   发布时间: 2011-06-09

本帖最后由 zooyo 于 2011-06-09 17:57 编辑
  1. sed ':a;/;$/!{N;s/\n */ /;ta};s/^ *//' file
复制代码
create unique index "informix".ipreregcn_id on "informix".preregcn  (id) using btree  in idxdbs ;
create index "informix".ihisdirectproduct_doapst on "informix" .hisdirectproduct (domainname,applytype,state) using btree  in idxdbs ;
create index "informix".ifundgift_us on "informix".fundgift (username)  using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_ad on "informix" .additionalsubproduct (additionalproductid) using btree   in datadbs ;
create index "informix".iadditionalsubproduct_do on "informix" .additionalsubproduct (domainname) using btree  in idxdbs  ;
create index "informix".iadditionalsubproduct_id on "informix" .additionalsubproduct (id) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_re on "informix" .additionalsubproduct (recordid) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_se on "informix" .additionalsubproduct (serial) using btree  in idxdbs ;
create index "informix".iadditionalsubproduct_us on "informix" .additionalsubproduct (username) using btree  in idxdbs ;
create index "informix".ilicenseaction_id on "informix".licenseaction  (id) using btree  in idxdbs ;
create index "informix".iwebtrustactiondomain_do on "informix" .webtrustactiondomain (domainname) using btree  in idxdbs  ;

作者: zooyo   发布时间: 2011-06-09



QUOTE:
create unique index "informix".ipreregcn_id on "informix".preregcn  (id) using btree  in idxdbs ;
c ...
zooyo 发表于 2011-06-09 17:46




    :handshake

作者: flyinweb_cu   发布时间: 2011-06-09