![]() |
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-09-15 12:37 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » How to use the for command to extract the last line of text content as a variable |
| Printable Version 3,090 / 10 |
| Floor1 26933062 | Posted 2006-12-22 12:38 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
The content of text a is as follows
0 1 2 3 4 5 Purpose: Run the following batch processing, %i% is equal to the content of the last line of document a, @echo off set /a i=%i%+1 echo %i% |
|
| Floor2 zh159 | Posted 2006-12-22 12:42 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
for %%i in (a.txt) do echo %%i
|
|
| Floor3 namejm | Posted 2006-12-22 12:51 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
```
@echo off for /f %%i in (a.txt) do set i=%%i set /a i=%i%+1 echo %i% [ Last edited by namejm on 2006-12-22 at 12:47 PM ] |
|
| Floor4 26933062 | Posted 2006-12-22 13:30 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
Thanks to the user on floor 3, it seems that you need to add /f after for. Also, thanks to the brother on floor 2. Why didn't you all add /f? According to what you said, what's displayed is the file name a.txt instead of the last line of the document content. Did I not make my question clear?
|
|
| Floor5 zh159 | Posted 2006-12-22 14:09 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Just wrote it casually, forgot to add "/f"
|
|
| Floor6 namejm | Posted 2006-12-23 01:48 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Hehe, I wrote it casually based on the 2F, but unexpectedly made a junior mistake.
|
|
| Floor7 lxmxn | Posted 2006-12-23 03:33 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by namejm at 2006-12-21 23:51: Don't understand why it's written like this. What's the purpose of adding 1? |
|
| Floor8 ccwan | Posted 2006-12-23 03:45 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Adding 1 is the purpose that the LZ's batch processing needs to accomplish.
|
|
| Floor9 lxmxn | Posted 2006-12-23 03:47 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Oh, I thought it was only extracting the last row. I read the question wrong. |
|
| Floor10 Li103Z | Posted 2008-01-01 18:46 |
| 初级用户 Posts 38 Credits 70 | |
|
Ask the expert, if I want to extract the elements of the first line and the second line in front, how to do it with the program
|
|
| Floor11 lxmxn | Posted 2008-01-02 13:46 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by Li103Z at 2008-1-1 18:46: Search for "ReadLine". |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |