Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set MSDOS variable equal to the contents of a text file

Status
Not open for further replies.

flyingsheep

Technical User
Apr 24, 2004
15
US
i have what i thought would be a fairly simple question which has now turned into a crusade, i am trying to set an variable equal to the contents of a text file, for example:

CONTENTS OF A TEXT FILE named text.txt:
hello world

PSEUDO-CODE (msdos) FOR WHAT I WANT TO DO:
set TEXTSTRING=[the_contents_of_text.txt]

SOME IDEAS THAT DIDNT WORK:
type text.txt>>somevariable
and
type text.txt|set somevariable


if you have any ideas on how i could do this, i am open to any ideas, thanks in advance,
alex
 
In batch:

@Set MYTEXT=text.TXT
@Set PARSEARG="eol=; tokens=1,2,3,4,5 "
@For /F %PARSEARG% %%j in (%MYTEXT%) Do SET TEXTSTRING=%%j %%k %%l %%m %%n
@cls
@Echo %TEXTSTRING%


Marc
If 'something' 'somewhere' gives 'some' error, expect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!

How Do I Get Great Answers To my Tek-Tips Questions? See faq219-2884
 
thank you both very much, i investigated both of your solutions, i'm sorry to have bothered you with such a simple question but i couldnt seem to find the answer, again, thank you very much :)

alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top