How to extract a word from a text file

T

TIA

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

Please post your query here:

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

hth
 
P

Pegasus [MVP]

TIA said:
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

TIA said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top