
126594
18.06.2016, aktualisiert um 23:09:44 Uhr
Batch for f Befehl erkennt doppelte Zeichen als eines
Hallo zusammen.
Ich versuche mich zur Zeit am Bearbeiten von Variablen in Batchdateien.
Eigentlich bin ich schon ganz gut voran gekommen.
Nun will ich eine Variable aufteilen, die durch ; getrennt sind nach jedem Querstrich soll der Text bis zum nächsteb Querstrich in eine extra Variable geschrieben werden.
Beispiel:
Variable=Text;Text1;Text2;;Text4;Text5;;Text7 oder Text;;Text2;Text3;Text4;Text5;;Text7
Schreibe ich jetzt die Vriablen mit:
for /f "tokens=1 delims=;" %%a in ("%variable%") do @set variable1=%%a
for /f "tokens=2 delims=;" %%a in ("%variable%") do @set variable2=%%a
for /f "tokens=3 delims=;" %%a in ("%variable%") do @set variable3=%%a
for /f "tokens=4 delims=;" %%a in ("%variable%") do @set variable4=%%a
usw.
So werden die doppelten ; als eines erkannt.
Die ; sind nicht immer an der gleichen Stelle, mein Ziel ist es, dass die Variable, die normalerweise zwischen 2 ; steht, einfach leer bleibt.
Geht das technisch überhaupt?
Viele Grüße und ein Danke für eure HIlfe ;)
Markus
Ich versuche mich zur Zeit am Bearbeiten von Variablen in Batchdateien.
Eigentlich bin ich schon ganz gut voran gekommen.
Nun will ich eine Variable aufteilen, die durch ; getrennt sind nach jedem Querstrich soll der Text bis zum nächsteb Querstrich in eine extra Variable geschrieben werden.
Beispiel:
Variable=Text;Text1;Text2;;Text4;Text5;;Text7 oder Text;;Text2;Text3;Text4;Text5;;Text7
Schreibe ich jetzt die Vriablen mit:
for /f "tokens=1 delims=;" %%a in ("%variable%") do @set variable1=%%a
for /f "tokens=2 delims=;" %%a in ("%variable%") do @set variable2=%%a
for /f "tokens=3 delims=;" %%a in ("%variable%") do @set variable3=%%a
for /f "tokens=4 delims=;" %%a in ("%variable%") do @set variable4=%%a
usw.
So werden die doppelten ; als eines erkannt.
Die ; sind nicht immer an der gleichen Stelle, mein Ziel ist es, dass die Variable, die normalerweise zwischen 2 ; steht, einfach leer bleibt.
Geht das technisch überhaupt?
Viele Grüße und ein Danke für eure HIlfe ;)
Markus
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 307586
Url: https://administrator.de/forum/batch-for-f-befehl-erkennt-doppelte-zeichen-als-eines-307586.html
Ausgedruckt am: 25.04.2025 um 05:04 Uhr
3 Kommentare
Neuester Kommentar

Hi.
This is normal behavior in a for-loop. Two or more characters which are delimiters and are directly flollowing each other, are combined as one.
You can avoid this with a replacement of those doubles before you loop.
But I would rather use a modern language like powershell, python or perl for csv processing, that's much more reliable.
Regards
This is normal behavior in a for-loop. Two or more characters which are delimiters and are directly flollowing each other, are combined as one.
You can avoid this with a replacement of those doubles before you loop.
set "variable=Text;Text1;Text2;;Text4;Text5;;Text7"
set "variable=%variable:;;=; ;%
for /f "tokens=1-7 delims=;" %%a in ("%variable%") do (
set "variable1=%%a"
set "variable2=%%b"
set "variable3=%%c"
set "variable4=%%d"
set "variable5=%%e"
)
Regards