免费注册 查看新帖 |

Chinaunix

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

Merges 2 files [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-09 04:58 |只看该作者 |倒序浏览
本帖最后由 fzhcl 于 2011-11-09 05:03 编辑

Hi Guys,

I have 2 files, name file1 and file2.    I need the result  like file3.
Can any one help me?  Thanks in advance.




file1:
application 401

   Heap has max size of 576 bytes
   Other Memory has max size of 8736 bytes
   Total: 16832397312 bytes

application 400

   Heap has max size of 376 bytes
   Other Memory has max size of 1686 bytes
   Total: 16832397312 bytes

application 406

   Heap has max size of 516 bytes
   Other Memory has max size of 134 bytes
   Total: 16832397312 bytes

application 399

   Heap has max size of 876 bytes
   Other Memory has max size of 166 bytes
   Total: 16832397312 bytes


  file2:
application 401

   Heap is of size 536 bytes
   Other Memory is of size 608 bytes
   Total: 262144 bytes

application 400

   Heap is of size 636 bytes
   Other Memory is of size 198 bytes
   Total: 262144 bytes

application 406

   Heap is of size 656 bytes
   Other Memory is of size 58 bytes
   Total: 655360 bytes

application 399

   Heap is of size 66 bytes
   Other Memory is of size 08 bytes
   Total: 262144 bytes



file3:
application 401    Heap has max size of 576 bytes   Other Memory has max size of 8736 bytes   Heap is of size 536 bytes   Other Memory is of size 608 bytes
application 400    Heap has max size of 376 bytes   Other Memory has max size of 1686 bytes   Heap is of size 636 bytes   Other Memory is of size 198 bytes
application 406    Heap has max size of 516 bytes   Other Memory has max size of 134 bytes    Heap is of size 656 bytes   Other Memory is of size 58 bytes
application 399    Heap has max size of 876 bytes   Other Memory has max size of 166 bytes    Heap is of size 66 bytes    Other Memory is of size 08 bytes

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
2 [报告]
发表于 2011-11-09 05:46 |只看该作者
本帖最后由 yinyuemi 于 2011-11-09 06:20 编辑

回复 1# fzhcl


    try:
  1. awk -vRS="application[^\n]+\n+" -vFS='\n' 'NR==1{m=RT}NR==FNR{a[m]=$1 OFS $2;m=RT;next}{print gensub(/\n/,"","g",m),a[m],$1,$2;m=RT}' f1 f2

  2. awk 'NF{++i%4~"[10]"?t=$0:a[t]=a[t] $0}END{for (i in a)print i a[i]}' cuf1 cuf2
复制代码

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
3 [报告]
发表于 2011-11-09 13:36 |只看该作者
  1. awk '/application/{app=$1} /Heap/{heap[app]=heap[app] OFS $1 OFS $2}END{for (i in heap) print i, heap[i]}' RS="" FS="\n" file1 file2
复制代码

论坛徽章:
3
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:51:162015年亚洲杯之阿曼
日期:2015-04-07 20:00:59
4 [报告]
发表于 2011-11-09 14:19 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
5 [报告]
发表于 2011-11-10 02:57 |只看该作者
楼上各位太强大了。 非常好的语句。
谢谢了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP