China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-09-24 23:29
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to read the values in a txt file and assign them to variables? View 2,383 Replies 19
Floor 16 Posted 2007-03-25 20:51 ·  中国 江苏 扬州 电信
中级用户
Credits 203
Posts 44
Joined 2003-08-14 00:00
23-year member
UID 8600
Gender Male
Status Offline
Originally posted by lxmxn at 2007-3-24 01:05 AM:
Assign the first line of the tmp.txt file to the St variable.



If I want to assign a specified line to a variable, how should I do it?
Floor 17 Posted 2007-03-25 21:16 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

To wjgyz740526:

Be more specific?

Is it based on line numbers or content?
Floor 18 Posted 2007-03-26 02:33 ·  中国 江苏 扬州 电信
中级用户
Credits 203
Posts 44
Joined 2003-08-14 00:00
23-year member
UID 8600
Gender Male
Status Offline
How to do it for the specified line number?

If it's content, we can use find, but after finding the content with find, do we need to distinguish between numerical values and text? Or can we just assign directly without distinction?
Floor 19 Posted 2007-03-26 03:09 ·  中国 福建 福州 连江县 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
22-year member
UID 29114
Gender Male
Status Offline
@echo off
set BL=
set /p hh=Please enter the line number:
for /f "skip=2 tokens=1,* delims=" %%i in ('find /n /v "" tmp.txt') do (if %%i==%hh% set BL=%%j)
echo BL=%BL%
pause

[ Last edited by balinger on 2007-3-26 at 03:11 AM ]
Floor 20 Posted 2007-03-27 02:17 ·  中国 江苏 扬州 电信
中级用户
Credits 203
Posts 44
Joined 2003-08-14 00:00
23-year member
UID 8600
Gender Male
Status Offline
Forum Jump: