Cut large files by line (linux split command Lite version), linuxsplit

Source: Internet
Author: User

Cut large files by line (linux split command Lite version), linuxsplit
Cutting large files by line (linux split command Lite version)

#-*-Coding: UTF-8-*-_ author _ = 'knowlifedeath ''' the Split command on Linux allows you to easily Split large files, this PY script is used to cut the file Python Version: 2.7 ''' import timeimport sysprint time on Windows based on the specified number of lines. strftime ('% Y-% m-% d % H: % M: % s', time. localtime (time. time () ''' the parameter '''bigfile = "E: \ Data \ Big.txt "OneUnitEnd = 1000000 # Number of split blocks ZeroFillWidth = 3 # zfill parameter is the serial number encoding length of small files seed = 0 # Number of Current Blocks UnitNo = 0 # Number of Current Blocks fSmallFile = open ('{0} \ samll1_1}.txt '. format (sys. pa Th [0], '0 '. zfill (ZeroFillWidth), 'w') fBigFile = open (BigFile) for line in fBigFile: rawLineData = line. strip ('\ n '). strip () if len (rawLineData )! = 0: seed + = 1 fSmallFile. write ('{0} \ n '. format (rawLineData) if seed = OneUnitEnd: fSmallFile. close () seed = 0 UnitNo + = 1 fSmallFile = open ('{0} \ samll1_12.16.txt '. format (sys. path [0], str (UnitNo ). zfill (ZeroFillWidth), 'w') # The last small file may be an empty file (full time) # a/w mode has little speed difference, hundreds of millions of data records are handled between 1 minute and a half to 2 minutes. # close multiple times. There will be no problem with fSmallFile. close () print time. strftime ('% Y-% m-% d % H: % M: % s', time. localtime (time. time ()))

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.