Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch script problem:splitting a big txt file into many 4000 lines  (Read 3260 times)

0 Members and 1 Guest are viewing this topic.

karlosss

    Topic Starter


    Beginner

    • Experience: Beginner
    • OS: Windows XP
    Batch script problem:splitting a big txt file into many 4000 lines
    script:
    Code: [Select]
    @echo off
        setlocal enableextensions disabledelayedexpansion

        set "nLines=4000"
        set "line=0"
        for /f %%a in ('type file.txt^|find /c /v ""') do set "fileLines=%%a"

        < "file.txt" (for /l %%a in (1 1 %fileLines%) do (
            set /p "data="
            set /a "file=1+line/%nLines%", "line+=1"
            setlocal enabledelayedexpansion
            >>"pass!file!.txt" echo(!data!
            endlocal
        ))

        endlocal

    Line 4001 is not empty,looks strange,here snapshot:


    On my Laptop this script works perfect on my pc and my rdp NO,i don't understand why
    « Last Edit: November 15, 2017, 07:12:07 AM by karlosss »

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch script problem:splitting a big txt file into many 4000 lines
    « Reply #1 on: November 15, 2017, 03:25:59 PM »
    What is generating the Text File? And curious why not just FTP the file from remote system to yourself vs splitting it into 4000 line chunks?

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Batch script problem:splitting a big txt file into many 4000 lines
    « Reply #2 on: November 15, 2017, 07:53:30 PM »
    You do not need the lines variable.  You could just write that line like this.
    Code: [Select]
    set /a "file=1+(%%a-1)/nLines"Not sure what your NULL issue is.  As far as I know, batch cannot generate a null character on its own.

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch script problem:splitting a big txt file into many 4000 lines
    « Reply #3 on: November 15, 2017, 07:57:33 PM »
    Quote
    Not sure what your NULL issue is.  As far as I know, batch cannot generate a null character on its own.

    Were both on same page with that one. That's why I also asked what is generating this text file.  ;D