中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-03 21:29
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How to read the values in a txt file and assign them to variables?
Printable Version  2,079 / 19
Floor16 wjgyz740526 Posted 2007-03-25 20:51
中级用户 Posts 44 Credits 203
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?
Floor17 lxmxn Posted 2007-03-25 21:16
版主 Posts 4,938 Credits 11,386

To wjgyz740526:

Be more specific?

Is it based on line numbers or content?
Floor18 wjgyz740526 Posted 2007-03-26 02:33
中级用户 Posts 44 Credits 203
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?
Floor19 balinger Posted 2007-03-26 03:09
中级用户 Posts 115 Credits 356
@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 ]
Floor20 wjgyz740526 Posted 2007-03-27 02:17
中级用户 Posts 44 Credits 203
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023