I found many topics on the problem of handling empty tokens, but i can't get it to work on my code. The only difference i can see is that i am using usebackq which the others didn't, but if i remove it, the rest of the code won't work. Could anyone point me to the right direction?
The code is supposed to take a csv, switch the value in the 3rd column with another value that is stored in Mitarbeiter.txt and do the same with the last value and it's pair in Lohnarten.txt, then write that into the new csv:
@Echo Off
SetLocal EnableDelayedExpansion
(Set Datei=lohn_prod.csv)
(Set MA=Mitarbeiter.txt)
(Set LA=Lohnarten.txt)
(Set Ziel=eGecko.csv)
For /F "Tokens=1-2 Delims=;" %%A In ('FindStr "[0-9]*;.*" "%MA%"') Do (
If Not Defined $[%%A] Set "$[%%A]=%%B")
For /F "Tokens=1-2 Delims=;" %%A In ('FindStr "[0-9]*;.*" "%LA%"') Do (
If Not Defined $[%%A] Set "_[%%A]=%%B")
For /F "Delims=" %%X In ("%Datei%") Do (
Set Line=%%X
Set Line=!Line:;=";"!
(For /F "UseBackQ EOL=; Skip=13 Tokens=1-7 Delims=;" %%A In ("!Line!") Do (
Call Echo=%%~A;%%~B;%%$[%%~C]%%;%%~D;%%~E;%%~F;%%_[%%~G]%%;)
)
)>%Ziel%
Exit/B
I am trying to encapsulate my semicolon-delimiters in quote marks and remove them before writing everything into the new file, but that doesn't work.
Instead of getting this csv:
15;01.09.2016;105;160,25;1;2100;210;
15;01.09.2016;105;40;1;;217;
15;01.09.2016;105;5;72;;;
15;01.09.2016;107;184;1;2213;210;
15;01.09.2016;107;7,25;1;;213;
15;01.09.2016;107;16;1;;216;
into this desired form:
15;01.09.2016;40200;160,25;1;2100;101;
15;01.09.2016;40200;40;1;;103;
15;01.09.2016;40200;5;72;;;
15;01.09.2016;40201;184;1;2213;101;
15;01.09.2016;40201;7,25;1;;423;
15;01.09.2016;40201;16;1;;102;
i instead get this, where the last values get moved into the 2nd last position if there is an empty token in front of them and thus also won't get replaced by the values in Lohnarten.txt:
15;01.09.2016;40200;160,25;1;2100;101;
15;01.09.2016;40200;40;1;217;;
15;01.09.2016;40200;5;72;;;
15;01.09.2016;40201;184;1;2213;101;
15;01.09.2016;40201;7,25;1;213;;
15;01.09.2016;40201;16;1;216;;