How to split large text file in windows?

后端 未结 6 1136
野的像风
野的像风 2020-12-12 13:30

I have a log file with size of 2.5 GB. Is there any way to split this file into smaller files using windows command prompt?

6条回答
  •  失恋的感觉
    2020-12-12 14:05

    Below code split file every 500

    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    REM Edit this value to change the name of the file that needs splitting. Include the extension.
    SET BFN=upload.txt
    REM Edit this value to change the number of lines per file.
    SET LPF=15000
    REM Edit this value to change the name of each short file. It will be followed by a number indicating where it is in the list.
    SET SFN=SplitFile
    
    REM Do not change beyond this line.
    
    SET SFX=%BFN:~-3%
    
    SET /A LineNum=0
    SET /A FileNum=1
    
    For /F "delims==" %%l in (%BFN%) Do (
    SET /A LineNum+=1
    
    echo %%l >> %SFN%!FileNum!.%SFX%
    
    if !LineNum! EQU !LPF! (
    SET /A LineNum=0
    SET /A FileNum+=1
    )
    
    )
    endlocal
    Pause
    

    See below: https://forums.techguy.org/threads/solved-split-a-100000-line-csv-into-5000-line-csv-files-with-dos-batch.1023949/

提交回复
热议问题