• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

How to extract a word from a text file

T

TIA

Flightless Bird
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
 
L

LD55ZRA

Flightless Bird
Please post your query here:

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

hth

"TIA" <TIA@discussions.microsoft.com> 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
 
P

Pegasus [MVP]

Flightless Bird
"TIA" <TIA@discussions.microsoft.com> 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.
 
H

HeyBub

Flightless Bird
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.
 
T

TIA

Flightless Bird
Thank you Pegasus !!!

- This is exactly what I needed it.

"Pegasus [MVP]" wrote:

>
>
> "TIA" <TIA@discussions.microsoft.com> 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.
>
> .
>
 
Top