Solved Extract substring from text file

June 28, 2019 at 03:32:19
Specs: DOS
I have a text with 3 parts first part is 4 characters (fixed length)
2nd part is from 5th characters until the character before \ (not fixed length)
3rd part first '\' on wards (not fixed length)

SET invar=1550maxwage\Thisisthemaxwage

SET firstvar=%invar:~0,4%
echo %firstvar% > %outfile%

this will give 1550

how to get the second and third substrings.
secondvar=maxwage
thirdvar=\Thisisthemaxwage


Appreciate your help!!


See More: Extract substring from text file

Reply ↓  Report •

#1
June 28, 2019 at 18:29:41
✔ Best Answer
maybe back up and use the tokens first, then lop off the first four:
for /f "tokens=1* delims=\" %%a in (test) do call :xx %%a %%b
goto :eof

:xx
set k=%1
set m=%k:~4%
set k=%k:~0,4%
echo %m% %k% %2
::------ end snip - not tested


Reply ↓  Report •
Related Solutions


Ask Question