Computing.Net > Forums > Disk Operating System > read txt file to variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

read txt file to variables

Reply to Message Icon

Name: josh
Date: July 31, 2002 at 00:07:10 Pacific
Comment:

i am using dos on a win 98 machine.
i have a bat file that will store information in a readme.txt file. it will store 1 word on the first line of this file, and 1 word on the second. so inside the file, it looks like this:

test
data

from a second, different bat file, i want to be able to pull each of these two words into seperate variables. where 'myvar1' contains 'test' and 'myvar2' contains 'data'. i am greatful for any help
thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 31, 2002 at 17:47:23 Pacific
Reply:

This should work:

===== BATCH SCRIPT BEGIN =====
@echo off
type README.TXT> %TEMP%.\T1.BAT

echo e100'SeT %%1='> %TEMP%.\T2.BAT
for %%? in (rcx 7 w q) do echo %%?>> %TEMP%.\T2.BAT
type nul> %TEMP%.\T3.BAT
DEBUG %TEMP%.\T3.BAT < %TEMP%.\T2.BAT > nul

type %TEMP%.\T1.BAT>> %TEMP%.\T3.BAT
FIND "SeT %%1=" < %TEMP%.\T3.BAT > %TEMP%.\T1.BAT
call %TEMP%.\T1.BAT myvar1
FIND/v "SeT %%1=" < %TEMP%.\T3.BAT > %TEMP%.\T1.BAT

DEBUG %TEMP%.\T3.BAT < %TEMP%.\T2.BAT > nul
type %TEMP%.\T1.BAT>> %TEMP%.\T3.BAT
FIND "SeT %%1=" < %TEMP%.\T3.BAT > %TEMP%.\T1.BAT
call %TEMP%.\T1.BAT myvar2

for %%? in (1 2 3) do del %TEMP%.\T%%?.BAT
===== BATCH SCRIPT END =====

Watch out for line wrapping!

Does the script look weird? Yes.
Does the script work? Yes.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0
Reply to Message Icon

Related Posts

See More


toshiba t1100 plus Unique .Com file request



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: read txt file to variables

Reading Txt file in dos mode www.computing.net/answers/dos/reading-txt-file-in-dos-mode/13836.html

read write txt files www.computing.net/answers/dos/read-write-txt-files-/13376.html

copy file to variable folder in bat www.computing.net/answers/dos/copy-file-to-variable-folder-in-bat/16199.html