![]() |
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-06 22:56 |
48,040 topics / 350,125 posts / today 1 new / 48,252 members |
| DOS批处理 & 脚本技术(批处理室) » "Small Function" to Read Specific Lines of a File (ReadLine2.bat) |
| Printable Version 3,154 / 5 |
| Floor1 lxmxn | Posted 2007-03-20 03:34 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Modified based on ReadLine.bat to read specific lines from a file. The usage is also relatively simple. Add "Call ReadLine2.bat <file name> <line number to read>" in the batch script. For example: "Call ReadLine2 system.ini 11 5 7 9" can read lines 5, 7, 9, and 11 of the system.ini file. The line numbers behind do not have a strict order of size. But the efficiency is not very high, and it is still acceptable for reading small files. ReadLine2.bat |
|
| Floor2 baomaboy | Posted 2007-03-20 03:51 |
| 银牌会员 Posts 554 Credits 1,513 | |
|
Bookmarked
|
|
| Floor3 HUNRYBECKY | Posted 2007-03-20 21:33 |
| 银牌会员 Posts 442 Credits 1,179 | |
|
Moderator lxmxn, why did you post in two places? For the convenience of management, it is suggested to move it under the original ReadLine1.bat. Thanks
|
|
| Floor4 lxmxn | Posted 2007-03-20 23:17 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by HUNRYBECKY at 2007-3-20 08:33: Isn't this called "posting in two places"? Although both are used to read specified lines of a file, their specific functions are different. One is to read consecutive lines, and the other is to read specific lines, and the effects are also different. |
|
| Floor5 29984365 | Posted 2007-04-07 04:42 |
| 初级用户 Posts 15 Credits 39 | |
| Floor6 z060053 | Posted 2008-07-25 14:07 |
| 新手上路 Posts 2 Credits 4 | |
|
@echo off
setlocal EnableDelayedExpansion set loop=0 set /a skipline=%2-1 for /f "tokens=1 skip=%skipline% delims=" %%a in (%1) do ( set /a loop=!loop!+1 if "!loop!" leq "%3" (echo %%a) else goto :eof ) goto :eo |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |