免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2421 | 回复: 11
打印 上一主题 下一主题

请教-合并问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-17 00:04 |只看该作者 |倒序浏览
请问要如何才能做到这样...

AA        123        select *
AA        123        from
AA        123        emp
AA        123        where id=1;
BB        333        select a,b,c
BB        333        from t1;       
AA        555        select *
AA        555        from
AA        555        t2 weher name='test';

----输出----
AA        123        select * from emp where id=1;
BB        333        select a,b,c from t1;
AA        555        select * from t2 where name='test';

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2006-08-17 01:12 |只看该作者

  1. #!/bin/bash
  2. set -o noglob
  3. tr -s ' '<urfile|cut -f1,2 -d' '|sort -u|\
  4. while read a b;do
  5.         str=$(grep "$a *$b" txt|xargs)
  6. echo $a $b ${str//$a $b}
  7. done>newfile
复制代码

论坛徽章:
0
3 [报告]
发表于 2006-08-17 12:02 |只看该作者
大大...我的没有bash...
而且bsh也无法run
-o: 0402-003 A specified flag is not valid for this command

请问有ksh的方法?谢谢

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
4 [报告]
发表于 2006-08-17 12:20 |只看该作者
awk '{if(a==$1" "$2){$1=$2="";printf $0}
else{printf (NR==1)?"":"\n";printf $0;a=$1" "$2}}
END{print ""}' urfile

有空看新手导航吧

论坛徽章:
0
5 [报告]
发表于 2006-08-17 13:55 |只看该作者
感谢各位帮忙

论坛徽章:
0
6 [报告]
发表于 2006-08-17 14:12 |只看该作者
各位大大..小弟又遇到问题了
AA        123                select *
AA        123                from
AA        123                emp
AA        123                where id=1;
BB        333 Wait For UOW        select a,b,c
BB        333 Wait For UOW        from t1;        
AA        555                select *
AA        555                from
AA        555                t2 weher name='test';
CC        666 (Ver V1-V3)        select *
CC        666 (Ver V1-V3)        from
CC        666 (Ver V1-V3)        t3 weher name='test1';
----输出----
AA        123                select * from emp where id=1;
BB        333 Wait For UOW        select a,b,c from t1;
AA        555                select * from t2 where name='test';
CC        666 (Ver V1-V3)        select * from t3 where name='test1';
请问不知要如何处理...

论坛徽章:
0
7 [报告]
发表于 2006-08-17 16:26 |只看该作者
想了个笨笨的方法,见笑了,水平有限,尤其是正则


  1. awk '{if(a==$1" "$2){$1=$2="";printf $0}
  2. else{printf (NR==1)?"":"\n";printf $0;a=$1" "$2}}
  3. END{print ""}' urfile
复制代码

这是waker兄的,用这个处理后是变成
AA        123                select *   from  emp  where id=1;
BB        333 Wait For UOW        select a,b,c  Wait For UOW from t1;
AA        555                select *  from  t2 weher name='test';
CC        666 (Ver V1-V3)        select *  (Ver V1-V3) from  (Ver V1-V3) t3 where name='test1';
再用sed

  1. sed -e 's/Wait For UOW/shit/' -e 's/(Ver V1-V3)/fuck/' -e
  2. 's/Wait For UOW//g' -e 's/(Ver V1-V3)//g' -e 's/shit/Wait For UOW/' -e 's/fuck/
  3. (Ver V1-V3)/' urfile
复制代码

AA        123                select *   from  emp  where id=1;
BB        333 Wait For UOW        select a,b,c   from t1;
AA        555                select *  from  t2 where name='test';
CC        666 (Ver V1-V3)        select *   from   t3 weher name='test1';
不知道用正则怎么写

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
8 [报告]
发表于 2006-08-17 18:03 |只看该作者
试试这个:
  1. awk '/select/{for (i=1;i<=NF;i++) a[i]=$i;printf $0" "};
  2.     !/select/{for (i=1;i<=NF;i++) {if ($i!=a[i]) printf $i" "}}
  3.     /;/{print ""}' your-file
复制代码

两种格式的文件通吃。^_^

论坛徽章:
0
9 [报告]
发表于 2006-08-17 18:32 |只看该作者
若有些不是;结束的要如何处理

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
10 [报告]
发表于 2006-08-17 19:02 |只看该作者
原帖由 rayylv 于 2006-8-17 18:32 发表
若有些不是;结束的要如何处理

老兄不是;结束的就是病句了,sql语言中要求语句必须用;结束。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP