Tugqi Biz
  • Home
  • Categories
  • Tags
  • Archives

Linux合并文件

闲聊¶

我爬一个网站数据时发现,需要4个小时.
汗!不能接受!我要并发!!!
于是我需要把抓回来的文件合并在一起


作为pythoner,第一个想到的是这种方案¶

import glob

source_files = glob.glob("*.txt") #这里可以是任何正则

result_file = open("result.txt", "a"):
for source_file in source_files:
    f = open(source_file, "r"):
    result_file.write(f.read())
    f.close()
result_file.close()

在看TLCL时发现可以这样¶

$ cat *.txt > result.txt

哈哈哈,就这么决定了


  • « Mysql 代码片段
  • Linux分割文件 »

Published

Mar 31, 2015

Category

IT

Tags

  • Linux 7
  • Python 15
  • Powered by Pelican. Theme: Elegant by Talha Mansoor