中国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-29 08:05
47,816 topics / 349,916 posts / today 0 new / 48,265 members
DOS批处理 & 脚本技术(批处理室) » How to extract lines 3 through 90 from a file?
Printable Version  1,776 / 9
Floor1 24634080 Posted 2007-04-27 00:59
初级用户 Posts 20 Credits 36
How can I extract lines 3 through 90 from a file and pass them to a new *.txt file! Thanks!
Floor2 slore Posted 2007-04-27 02:03
铂金会员 Posts 2,478 Credits 5,212
skip 2 lines, read once >new.txt

skip 89 lines, read once >>new.txt
Floor3 everest79 Posted 2007-04-27 02:07
金牌会员 Posts 1,127 Credits 2,564
I seem to have written one before, but I can't find it.
Floor4 ansipeter Posted 2007-04-27 02:15
中级用户 Posts 130 Credits 269
Floor5 zhoushijay Posted 2007-04-27 02:24
高级用户 Posts 375 Credits 845
Could post #4 explain the code?
Floor6 slore Posted 2007-04-27 02:32
铂金会员 Posts 2,478 Credits 5,212
@echo off

for /f "skip=2 delims=" %%i in (1.txt) do (
@echo %%i>>Out.txt
goto Next
)
:Next
for /f "skip=89 delims=" %%i in (1.txt) do (
@echo %%i>>Out.txt
goto Exit
)
:Exit
pause>nul


I still think my own way is better... If there are a lot of lines, the FINDSTR above has to add line numbers to the whole text... and then filter...
Floor7 lililulula Posted 2007-04-27 06:02
中级用户 Posts 138 Credits 302
If what the OP wants is the content from line 3 to line 90, then you can do it like this
@echo off
for /l %%a in (3,1,90) do call :need %%a
:need
for /f "tokens=1* delims=:" %%i in ('findstr /n . 1.txt') do if %%i==%1 echo %%j>>2.txt
Floor8 lxmxn Posted 2007-04-27 12:29
版主 Posts 4,938 Credits 11,386
Floor9 zh159 Posted 2007-04-27 23:45
金牌会员 Posts 1,467 Credits 3,687
Output in the original format, cannot output blank lines


Can output blank lines, but each line must not contain the “line number:” characters that are the same as the line number, and it cannot output the “!、:” characters or the characters enclosed by “!、:” on the same line


[ Last edited by zh159 on 2007-4-27 at 10:49 AM ]
Floor10 vkill Posted 2007-04-28 00:38
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023