Getting string in text by position

Dell / Centrino
January 13, 2009 at 03:58:32
Specs: Windows XP, 111
i have a text file where the first line looks like the follwing:
BFH0000000101NIC512 201PROD0901071944CY000930
i need to extract the value started at position 13 from the first line.
i did got the first line and when i try to extract the value by position it fails
below is what i write:
setlocal EnableDelayedExpansion
cd c:\BSP\Unzipped
for /f "tokens=*" %%x in ('dir /a-d /b *.*') do (
for /f "delims=" %%a in ('findstr /r "PROD"[0-9] %%x ') do (
set line=%%a&set city=%line:~13,3%
)
Echo %city%
)


THE ABOVE IS NOT SUCCEEDED IN GETING THE VALUE OF CITY.
ANY HELP IS HIGLY APPRECIATED?



See More: Getting string in text by position

Report •


#1
January 13, 2009 at 04:18:20
If it's just one file you shouldn't need the first FOR loop.

Beyond that, if the string needed is in the first line you shouldn't need findstr, nor FIND.

===========================================
@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (my.txt) do (
set str=%%a
set str=!str:~12,3!
echo !str!
goto :eof
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •
Related Solutions


Ask Question