I want to execute csv files result from joined each file inside one folder with batch script. Before I try with nested loop and show all rows, it’s work. But I want to add some logic to process all rows with adjust each header/column when loops is processing. This is how I show all rows with nested loop and joined each csv files:
for /f "usebackq delims=|" %%f in (`dir /b "C:Usersmyfolder*.csv"`) do (
for /f "usebackq tokens=* delims=," %%i in (%%f) do (
echo %%i >>joinedfiles.csv
)
)
Only add other logic, I try to separate each line with header:
set "oldFileHeader=NO,NO ANTRIAN,NO SPAJ,TIPE DOKUMEN,TGL KIRIM,KEY"
set "newFileHeader=No Urut,BOX_NO,NoAntrian,NoPolis,Jenis Dokumen,Jenis Transaksi,Tgl Penerimaan,NoAntrian NB,Tgl Penerimaan NB,Key"
for /f "usebackq delims=|" %%f in (`dir /b "C:Usersmyfolder*.csv"`) do (
for /f "usebackq tokens=* delims=," %%i in (%%f) do (
set /a count+=1
set "line=%%i"
if "!line!" EQU "!newheader!" (
set /a lineNumber=!count!-1
for /f "usebackq tokens=* delims=," %%a in (%%i) do (
echo %%a
)
)
if "!line!" EQU "!oldheader!" (
set /a lineNumber=!count!-1
echo count: %lineNumber%
for /f "skip=%lineNumber% usebackq tokens=1-6 delims=," %%a in (%%i) do (
set first=%%a
set second=%%b
set third=%%c
set fourth=%%d
set fifth=%%e
echo !first!,!second!,!third!,!fourth!,!fifth!
)
)
)
)
Thats code above is not working because executed lines only header, not a each row based on header file.
My question is, how to executed thats file and separate based on header.