By Dustin

2011-05-04 15:58:54 8 Comments

Im currently looking for a method to set variables in a windows batch file from linkes in txt document.

So for example, if the text file reads:

I can hopefully output them to variables in the batch. Example:

set var1="Line one of text file, ex:"
set var2="Line two of text file, ex :"
set var3="Line three of text file, ex:"

Any help is appreciated, thanks in advance!


@Navigatron 2013-01-05 06:13:05

Here ya go! Have fun with this one.

set /p var1=
set /p var2=
set /p var3=

Lands you with the same results!

@rahuldottech 2016-06-27 10:01:43

This is awesome!

@illusivetech 2018-01-25 21:40:36

Mucho grande divertida

@Anders 2011-05-04 16:33:18

The FOR /F loop command can be used to read lines from a text file:

@echo off
set vidx=0
for /F "tokens=*" %%A in (sites.txt) do (
    SET /A vidx=!vidx! + 1
    set var!vidx!=%%A
set var

You end up with:


@forsvarir 2011-05-04 16:41:22

Well, you learn something new everyday!

@Dustin 2011-05-04 16:46:28

Absolutely brilliant! You're a life saver. So simple too. Thanks a lot!

@kamlendra 2017-02-26 05:55:25

hi Anders, what if i want to take only website addrerss as out put? current output is "" desired out put is ""

Related Questions

Sponsored Content

18 Answered Questions

[SOLVED] Why should text files end with a newline?

16 Answered Questions

[SOLVED] How can I pass arguments to a batch file?

41 Answered Questions

[SOLVED] How do I find all files containing specific text on Linux?

23 Answered Questions

[SOLVED] Batch file to delete files older than N days

27 Answered Questions

5 Answered Questions

[SOLVED] Split long commands in multiple lines through Windows batch file

  • 2008-09-16 03:04:34
  • Dan
  • 353866 View
  • 635 Score
  • 5 Answer
  • Tags:   batch-file

2 Answered Questions

[SOLVED] Text editor to open big (giant, huge, large) text files

14 Answered Questions

[SOLVED] Windows batch files: .bat vs .cmd?

2 Answered Questions

[SOLVED] Windows Batch: Loop through to echo a set of variables

  • 2013-09-03 03:59:37
  • Brian
  • 3469 View
  • 0 Score
  • 2 Answer
  • Tags:   batch-file

Sponsored Content