[Batch] String Extraction
Solved
jejeTech
Posted messages
83
Status
Member
-
logon313 Posted messages 50 Status Member -
logon313 Posted messages 50 Status Member -
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.
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 answers
-
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-
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.
-