Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2011 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1423782 to your computer and use it in GitHub Desktop.
Save anonymous/1423782 to your computer and use it in GitHub Desktop.
log merge
#! /usr/bin/python
# -*- coding:utf-8 -*-
#マージ用関数
#各ファイルの同じ行を連結
def merge_file(list_n, list_c10, list_c50, lines):
merged_list =[]
i = 0
while i < lines:
line = list_n[i].replace("\n"," ")+list_c10[i].replace("\n"," ")+list_c50[i]
merged_list.append(line)
i = i+1
return merged_list
if __name__ == '__main__':
#ファイル名の指定
normal = "net_n.log"
c10 = "net_10.log"
c50 = "net_50.log"
all = "net_all.log"
#ファイルオープン
log_normal = open(normal,"r")
log_c10 = open(c10,"r")
log_c50 = open(c50,"r")
log_all = open(all,"w")
#各ファイルをリスト型に変換
list_n = log_normal.readlines()
list_c10 = log_c10.readlines()
list_c50 = log_c50.readlines()
#各ファイルの行数が一致した場合のみマージ用関数コール
if len(list_n) == len(list_c10):
if len(list_c10) == len(list_c50):
list = merge_file(list_n, list_c10, list_c50, len(list_c50))
log_all.writelines(list)
print "process done. check output file:"+all
else:
print "log files do not match\n"
else:
print "log files do not match\n"
#ファイルクローズ
log_normal.close()
log_c10.close()
log_c50.close()
log_all.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment