How to extract a word from a text file

  • Thread starter Thread starter TIA
  • Start date Start date
T

TIA

Guest
I need help to create a small batch script /procedure that extracts a piece

of information from a text file:



-Skipp first two lines in a file

-Extract a piece of text from the 11-th character until the first blank /

space character and store it into an environment variable.

- Compare this info against a constant



Any examples ideas please ?



TIA
 
Please post your query here:



news://msnews.microsoft.com/microsoft.public.scripting.vbscript



hth



"TIA" wrote in message

news:416630B6-8A60-4B7E-AB50-1818361CEA66@microsoft.com...

>I need help to create a small batch script /procedure that extracts a piece

> of information from a text file:

>

> -Skipp first two lines in a file

> -Extract a piece of text from the 11-th character until the first blank /

> space character and store it into an environment variable.

> - Compare this info against a constant

>

> Any examples ideas please ?

>

> TIA
 
"TIA" wrote in message

news:416630B6-8A60-4B7E-AB50-1818361CEA66@microsoft.com...

> I need help to create a small batch script /procedure that extracts a

> piece

> of information from a text file:

>

> -Skipp first two lines in a file

> -Extract a piece of text from the 11-th character until the first blank /

> space character and store it into an environment variable.

> - Compare this info against a constant

>

> Any examples ideas please ?

>

> TIA




Here you go. Do not retype the code - just copy & paste it

..

@echo off

SetLocal EnableDelayedExpansion

set file=d:\temp\dir.txt

set count=0



for /F "delims=" %%a in ('type "%file%"') do (

if !count! EQU 2 (

set Line=%%a

for /F %%b in ('echo !Line:~10!') do set Var=%%b

goto ExitLoop

)

set /a count=!count! + 1

)

:ExitLoop

echo The string is %Var%



The code is subject to the usual "poison-character syndrome". If you need

something more robust then a VB Script solution would be appropriate, as

LD55ZRA suggested.
 
TIA wrote:

> I need help to create a small batch script /procedure that extracts a

> piece of information from a text file:

>

> -Skipp first two lines in a file

> -Extract a piece of text from the 11-th character until the first

> blank / space character and store it into an environment variable.

> - Compare this info against a constant

>

> Any examples ideas please ?

>




Almost any programmer, in any language, can whip this out in a trice.

Shouldn't cost much.
 
Thank you Pegasus !!!



- This is exactly what I needed it.



"Pegasus [MVP]" wrote:



>

>

> "TIA" wrote in message

> news:416630B6-8A60-4B7E-AB50-1818361CEA66@microsoft.com...

> > I need help to create a small batch script /procedure that extracts a

> > piece

> > of information from a text file:

> >

> > -Skipp first two lines in a file

> > -Extract a piece of text from the 11-th character until the first blank /

> > space character and store it into an environment variable.

> > - Compare this info against a constant

> >

> > Any examples ideas please ?

> >

> > TIA


>

> Here you go. Do not retype the code - just copy & paste it

> ..

> @echo off

> SetLocal EnableDelayedExpansion

> set file=d:\temp\dir.txt

> set count=0

>

> for /F "delims=" %%a in ('type "%file%"') do (

> if !count! EQU 2 (

> set Line=%%a

> for /F %%b in ('echo !Line:~10!') do set Var=%%b

> goto ExitLoop

> )

> set /a count=!count! + 1

> )

> :ExitLoop

> echo The string is %Var%

>

> The code is subject to the usual "poison-character syndrome". If you need

> something more robust then a VB Script solution would be appropriate, as

> LD55ZRA suggested.

>

> .

>
 
Back
Top