注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

星期五

明天不上班

 
 
 

日志

 
 
关于我

一个特立独行的Java程序员,比较宅,上上网,写博客,听音乐,看电影。

网易考拉推荐

对cvs log输出进行时间排序  

2012-02-28 22:15:38|  分类: Ruby |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
先观察一下cvs log输出(cvs.log)

RCS file: /cvs/CVS/test/com/hjzheng/test/Test.java,v
head: 1.3
branch:
locks: strict
keyword substitution: b
total revisions: 5;     selected revisions: 5
description:
----------------------------
revision 1.3
date: 2011-03-16 15:16:18 +0800;  author: hjzheng;  state: Exp;  lines: +1 -1;
branches:  1.3.14;
merge code from other branch 
----------------------------
revision 1.2
date: 2010-10-27 11:32:07 +0800;  author: hjzheng;  state: Exp;  lines: +1 -4;
branches:  1.2.2;
----------------------------
revision 1.1
date: 2010-07-05 16:59:34 +0800;  author: hjzheng;  state: Exp;
copy from other java file
----------------------------
revision 1.2.2.1
date: 2011-01-19 15:25:03 +0800;  author: hjzheng;  state: Exp;  lines: +1 -1;
update  background color
----------------------------
revision 1.3.14.1
date: 2012-02-22 11:12:53 +0800;  author: hjzheng;  state: dead;  lines: +0 -0;  commitid: WDFC9kdtexnsj6Uv;
remove redundant code
=============================================================================

对log进行解析让description后时间排序

#!/usr/bin/ruby -w
#author @hjzheng

log_file = ARGV[0]
log_array = []
File.open(log_file){|file|
file.each_line{|line|
log_array << line
}
}

boundary_index = log_array.index("description:\n")
puts boundary_index

log_head = log_array[0..boundary_index]

log_description = log_array[boundary_index+1..log_array.length]
#clear jam
log_description.shift()
log_description.pop()
log_description.pop()
#
log_string = log_description.join("")
#
log_new_description = log_string.split("----------------------------\n")

log_new_description = log_new_description.sort{|a, b|
start_index_a = a.index("date:")
end_index_a = a.index(";")

start_index_b = b.index("date:")
end_index_b = b.index(";")

b[start_index_b..end_index_b] <=> a[start_index_a..end_index_a]
}


log_array = log_head + log_new_description.collect{|x| "----------------------------\n"+x}

puts log_array


测试

hjzheng@hjzheng-ThinkPad-T520 ~/ruby_script $ ./sort_log.rb cvs.log
6
RCS file: /cvs/CVS/test/com/hjzheng/test/Test.java,v
head: 1.3
branch:
locks: strict
keyword substitution: b
total revisions: 5; selected revisions: 5
description:
----------------------------
revision 1.3.14.1
date: 2012-02-22 11:12:53 +0800; author: hjzheng; state: dead; lines: +0 -0; commitid: WDFC9kdtexnsj6Uv;
remove redundant code
----------------------------
revision 1.3
date: 2011-03-16 15:16:18 +0800; author: hjzheng; state: Exp; lines: +1 -1;
branches: 1.3.14;
merge code from other branch
----------------------------
revision 1.2.2.1
date: 2011-01-19 15:25:03 +0800; author: hjzheng; state: Exp; lines: +1 -1;
update background color
----------------------------
revision 1.2
date: 2010-10-27 11:32:07 +0800; author: hjzheng; state: Exp; lines: +1 -4;
branches: 1.2.2;
----------------------------
revision 1.1
date: 2010-07-05 16:59:34 +0800; author: hjzheng; state: Exp;
copy from other java file




  评论这张
 
阅读(579)| 评论(0)
推荐

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017