Computing.Net > Forums > Programming > Assign 1st line in file to variable in batch

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.

Assign 1st line in file to variable in batch

Reply to Message Icon

Name: gman8
Date: October 27, 2009 at 08:13:00 Pacific
OS: Windows XP
Product: Nt / Batch
Subcategory: Batch
Comment:

I have a text file and the first line is a number. How can I get this number assigned to a variable inside a batch file?



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: October 27, 2009 at 13:53:46 Pacific
Reply:

Hi gman8

Change "set Num=%%a & set Num & exit /b"
to "set Num=%%a & & exit /b" if you dont
the variable Num displayed on screen.
Below is all one line.

@echo off
for /f "tokens=1 delims= " %%a in (GetNum.txt) do set Num=%%a & set Num & exit /b


0
Reply to Message Icon

Related Posts

See More


Eval a batch var whose va... Random Numbers according ...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Assign 1st line in file to variable in batch

PsExec issue in batch file www.computing.net/answers/programming/psexec-issue-in-batch-file/16183.html

Rename file to system date batch www.computing.net/answers/programming/rename-file-to-system-date-batch/15335.html

batch to change lines in a file www.computing.net/answers/programming/batch-to-change-lines-in-a-file/18174.html