Read string from file

December 20, 2011 at 00:48:53
Specs: Windows 7
I need some help with a bacth file
I have a file that looks like this

PD2992,4468;PD2740,4516;PD2540,4552;PD2340,4584;PD2140,4612;PD1940,4640;PD2508,6372;PD4464,6200;PD5928,6068;LT;DI0,1000;SI1.117600,1.693333;PU1171,0;LB1S12002T236 * LENGTE: 0,958 m * BREEDTE: 1,450 m * 18/11/11;LT;PU1412,0;PD39716,0;PD39716,58000;PD1412,58000;PD1412,0;LT;DI1000,0;SI0.838200,1

I need to get the value between * *
I used this
@echo off
findstr /m "LENGTE" *.hpgl > results.txt
if %errorlevel%==0 (
echo Found! logged files into results.txt
) else (
echo No matches found
)
It will list me all the files in the folder containing "LENGTE"

But I need the value behind "LENGTE" so I need to get Filename and LENGTE: 0,958 m

I tried this

if exist lijst.txt del lijst.txt
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=1,2 delims=;," %%A IN ('FINDSTR /B/L/C "LENGTE" *.HPGL /B') DO (
SET LENGTE=%%B
SET /A LENGTE = !LENGTE:~10!
>> lijst.txt ECHO %%A !LENGTE!
)
ENDLOCAL

But it does not work
Can somebody help me with this.
Thank you


See More: Read string from file

Report •


#1
December 21, 2011 at 09:16:43
Hi JeanPaul

This help

@echo off
cls
findstr /m "LENGTE" *.hpgl > results.txt
if %errorlevel%==0 (
echo Found! logged files into results.txt
) else (
echo No matches found
)
echo.


SetLocal EnableDelayedExpansion
if exist lijst.txt del lijst.txt
for /f %%a in (results.txt) do (
type %%a | find /i "LENGTE" > lijst.txt
for /f "tokens=1-5 delims=*:" %%b in (lijst.txt) do (
echo %%a %%c %%d %%e %%f
)
)


Report •

#2
December 21, 2011 at 11:07:39
Hi Dtech10 thank you for helping me with this problem, but it still does not work,
all I get is

";PU;SP1;PW0.088194;LT;PU14500,47436;PD14500,47236;PD24080,47236;LT;PU37324,47236;PD37324,45216;PD1412,45216;PD1412,47236;PD1692,47236;LT;PU1412,47236;PD1412,49256;PD37324,49256;PD37324,47236;PD37044,47236;LT;PU37324,47236;PD37324,45216;PD1412,45216;PD1412,47236;PD1692,47236;LT;PU1412,47236;PD1412,49256;PD37324,49256;PD37324,47236;PD37044,47236;LT;PU36924,47236;PD36924,456"
and not
LENGTE: 1,568 m

I tried to change delims=*: into delims=^*: delims=~*:" delims=: but always the same result.

I have an batch file that works very good, and searche on PS in PLT files

if exist lijst.txt del lijst.txt
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=1,2 delims=:," %%A IN ('FINDSTR /B/L/C:"PS" D:DIR *.plt /B') DO (
SET PS=%%B
SET /A PS = !PS:~2! / 400
>> lijst.txt ECHO %%A !PS!
)
ENDLOCAL


I tried to Change PS to LENGTE but than it does not work any more.
I tried so many different ways already, I am a little bit stuck with this.
HPGL files have the length somewhere at the end of the file as PLT files have the length on the first line as PS

If you have any other idea let me know.
Thank you

JP


Report •

Related Solutions


Ask Question