[Batch] String Extraction

Solved
jejeTech Posted messages 83 Status Membre -  
logon313 Posted messages 50 Status Membre -
Hi,

I have a problem with manipulating a string. I have a file (temp2.txt) that contains a string of characters like this:

1:4162

What I want to do is extract the number "4162" to temporarily place it in a variable. I am using the FOR command to achieve this.

Here is the line that should allow me to perform this extraction:

FOR /F "eol=: tokens=1 " %i in temp2.txt do @echo %i

Thank you in advance for your help.

15 réponses

Pool Orion Posted messages 124 Status Membre 55
 
Sorry, I had to look around a bit too. You need to use the variables with the double percentage sign.

-->

pause
@echo off
FOR /F "tokens=1,2 delims:;" %%i in (temp2.txt) do @echo %%i and %%j
pause

gives the result 1 and 4162

--
Pool Orion
20
ga1841 Posted messages 6 Status Membre 7
 
I noticed that you have a good command of the FOR command and I have a problem with a line of FOR command. This line is correct because when run alone in the command prompt, I get the desired result, but when integrated into the rest of my script, it doesn't work at all. If you know the reason and the solution, please let me know. Thank you in advance.
-1
xed > ga1841 Posted messages 6 Status Membre
 
Hello,

In a FOR loop when you run the command directly, there is 1 % in front of your variable, for example %i
But when you put this loop in a Batch file, you need to use it twice, so %%i

That's all.
0