Computer Hope

Microsoft => Microsoft DOS => Topic started by: karlosss on November 15, 2017, 07:01:07 AM

Title: Batch script problem:splitting a big txt file into many 4000 lines
Post by: karlosss on November 15, 2017, 07:01:07 AM
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:
(http://i63.tinypic.com/2a5gkl.jpg)

On my Laptop this script works perfect on my pc and my rdp NO,i don't understand why
Title: Re: Batch script problem:splitting a big txt file into many 4000 lines
Post by: DaveLembke 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?
Title: Re: Batch script problem:splitting a big txt file into many 4000 lines
Post by: Squashman 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.
Title: Re: Batch script problem:splitting a big txt file into many 4000 lines
Post by: DaveLembke 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