Hi there,
I found this topic which actually solved my problem on splitting the csv file into multiple ones, split a 100000 line csv into 5000 line csv files with DOS batch, however it is already closed so I decided to open a new one.
The solution given to the previous thread was this and it actually worked:
=======================================================
@echo off
setlocal ENABLEDELAYEDEXPANSION
REM Edit this value to change the name of the file that needs splitting. Include the extension.
SET BFN=BigFile.csv
REM Edit this value to change the number of lines per file.
SET LPF=5000
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
=======================================================
However, after splitting the file, I noticed that only the first split had the column headers while the remaining ones does not have them. Is it possible to do that through batch? If yes, what code can I include in the code given above?
Thanks.
I found this topic which actually solved my problem on splitting the csv file into multiple ones, split a 100000 line csv into 5000 line csv files with DOS batch, however it is already closed so I decided to open a new one.
The solution given to the previous thread was this and it actually worked:
=======================================================
@echo off
setlocal ENABLEDELAYEDEXPANSION
REM Edit this value to change the name of the file that needs splitting. Include the extension.
SET BFN=BigFile.csv
REM Edit this value to change the number of lines per file.
SET LPF=5000
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
=======================================================
However, after splitting the file, I noticed that only the first split had the column headers while the remaining ones does not have them. Is it possible to do that through batch? If yes, what code can I include in the code given above?
Thanks.