|  | 
 
| bagpipe 银牌会员
 
      DOS联盟捡破烂的
 
 
 积分 1144
 发帖 425
 注册 2005-10-20
 来自 北京
 状态 离线
 | 
|  『楼 主』:
 [资料]如何提取不同行上的内容
 
使用 LLM 解释/回答一下 
 
 
中文翻译见18楼(版务 by HAT @ 2009-01-04)
 原在#27,修正至#18 (管理员注 2009-1-5)
 This page shows how to read specific lines from a text file. There are many ways to have the for /f command read the input file, for instance:-
 for /f "delims=" %%a in (input.txt) do ...
 
 for /f "delims=" %%a in ('type input.txt') do ...
 
 for /f "delims=" %%a in ('more ^< input.txt') do ...
 
 However, only the last method (using the more command) will give consistent results across Windows NT, 2000, XP and 2003. The first method does not recognise unicode files. Also, the usebackq switch must be used if the input filename contains spaces. The second method, using the type command, also fails to recognise unicode files on Windows 2000, XP and 2003 if the input file does not begin with a bit order mark (BOM).
 
 In all the examples, assume the contents of of the file numbers.txt to be:-
 
 one
 two
 three
 four
 five
 six
 seven
 eight
 nine
 ten
 
 Displaying the first line
 
 This example prints one.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set "first="
 for /f "delims=" %%a in ('more ^< numbers.txt') do (
 if not defined first set first=%%a
 )
 echo/%first%
 
 Displaying the first X lines
 
 This example prints one, two and three.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set "lines=3"
 set i=-1
 set "ok="
 for /f "delims=" %%a in ('more ^< numbers.txt') do (
 set/a i+=1 & for /f %%z in ('echo/%%i%%') do (
 if "%%z"=="%lines%" set ok=1
 )
 if not defined ok echo/%%a
 )
 
 Displaying the last line
 
 This example prints ten.
 
 @echo off & setlocal ENABLEEXTENSIONS
 for /f "delims=" %%a in ('more ^< numbers.txt') do set "last=%%a"
 echo/%last%
 
 Displaying the last X lines
 
 This example prints nine and ten.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set "lines=2"
 for /f %%a in ('find/c /v "" ^< numbers.txt') do set/a skip=%%a-lines
 for /f "delims=" %%a in ('more/e +%skip% ^< numbers.txt') do (
 echo/%%a
 )
 
 Displaying the Nth line
 
 This example prints three. Note that instead of using the more command's /e switch, the skip option could have been used with the for /f command, however, this fails is it is set to any number less than one.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set LineNo=3
 set "line="
 set/a LineNo-=1
 for /f "delims=" %%a in ('more/e +%LineNo% ^< numbers.txt') do (
 if not defined line set "line=%%a"
 )
 echo/%line%
 
 Displaying the Nth line plus X number of lines
 
 This example prints five and six.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set start=5
 set "lines=2"
 set/a i=-1,start-=1
 set "ok="
 for /f "delims=" %%a in ('more/e +%start% ^< numbers.txt') do (
 set/a i+=1 & for /f %%z in ('echo/%%i%%') do (
 if "%%z"=="%lines%" set ok=1
 )
 if not defined ok echo/%%a
 )
 
Chinese translation see post 18 (Moderation by HAT @ 2009-01-04)
 Originally at #27, corrected to #18 (Administrator note 2009-1-5)
 This page shows how to read specific lines from a text file. There are many ways to have the for /f command read the input file, for instance:-
 for /f "delims=" %%a in (input.txt) do ...
 
 for /f "delims=" %%a in ('type input.txt') do ...
 
 for /f "delims=" %%a in ('more ^< input.txt') do ...
 
 However, only the last method (using the more command) will give consistent results across Windows NT, 2000, XP and 2003. The first method does not recognise unicode files. Also, the usebackq switch must be used if the input filename contains spaces. The second method, using the type command, also fails to recognise unicode files on Windows 2000, XP and 2003 if the input file does not begin with a bit order mark (BOM).
 
 In all the examples, assume the contents of of the file numbers.txt to be:-
 
 one
 two
 three
 four
 five
 six
 seven
 eight
 nine
 ten
 
 Displaying the first line
 
 This example prints one.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set "first="
 for /f "delims=" %%a in ('more ^< numbers.txt') do (
 if not defined first set first=%%a
 )
 echo/%first%
 
 Displaying the first X lines
 
 This example prints one, two and three.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set "lines=3"
 set i=-1
 set "ok="
 for /f "delims=" %%a in ('more ^< numbers.txt') do (
 set/a i+=1 & for /f %%z in ('echo/%%i%%') do (
 if "%%z"=="%lines%" set ok=1
 )
 if not defined ok echo/%%a
 )
 
 Displaying the last line
 
 This example prints ten.
 
 @echo off & setlocal ENABLEEXTENSIONS
 for /f "delims=" %%a in ('more ^< numbers.txt') do set "last=%%a"
 echo/%last%
 
 Displaying the last X lines
 
 This example prints nine and ten.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set "lines=2"
 for /f %%a in ('find/c /v "" ^< numbers.txt') do set/a skip=%%a-lines
 for /f "delims=" %%a in ('more/e +%skip% ^< numbers.txt') do (
 echo/%%a
 )
 
 Displaying the Nth line
 
 This example prints three. Note that instead of using the more command's /e switch, the skip option could have been used with the for /f command, however, this fails is it is set to any number less than one.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set LineNo=3
 set "line="
 set/a LineNo-=1
 for /f "delims=" %%a in ('more/e +%LineNo% ^< numbers.txt') do (
 if not defined line set "line=%%a"
 )
 echo/%line%
 
 Displaying the Nth line plus X number of lines
 
 This example prints five and six.
 
 @echo off & setlocal ENABLEEXTENSIONS
 set start=5
 set "lines=2"
 set/a i=-1,start-=1
 set "ok="
 for /f "delims=" %%a in ('more/e +%start% ^< numbers.txt') do (
 set/a i+=1 & for /f %%z in ('echo/%%i%%') do (
 if "%%z"=="%lines%" set ok=1
 )
 if not defined ok echo/%%a
 )
 
 
 
 
 
 |  | 
|  2006-7-3 10:21 |  | 
|  | 
 
| tclshx 中级用户
 
    
 
 
 积分 249
 发帖 64
 注册 2005-6-3
 状态 离线
 | 
| 『第 2 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by bagpipe at 2006-7-3 10:21 AM:This page shows how to read specific lines from a text file. There are many ways to have the for /f command read the input file, for instance:-
 
 for /f "delims=" %%a in (input.txt) do . ...
 
对一我们新鸟来说太难,要是有中文说明就好了. 
对于我们这些新手来说太难了,如果有中文说明就好了。
 (注:原句“对一我们新鸟来说太难,要是有中文说明就好了.”中“对一”应为“对于”的笔误,已按正确表述翻译)
 
 
 
 |  | 
|  2006-7-5 23:37 |  | 
|  | 
 
| hanbsome 初级用户
 
   
 
 
 
 积分 36
 发帖 14
 注册 2006-4-29
 状态 离线
 | 
| 『第 3 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
的确就像二楼说的那样  太深奥了 看不懂啊 
Indeed, just like what the second floor said, it's too profound. I can't understand it. 
 
 
 |  | 
|  2006-7-6 16:07 |  | 
|  | 
 
| pengfei 银牌会员
 
      
 
 
 积分 1218
 发帖 485
 注册 2006-7-21
 来自 湖南.娄底
 状态 离线
 | 
| 『第 4 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
楼主能不能具体解释一下. 
Can the poster specifically explain? 
 
 
 |  | 
|  2006-7-26 22:21 |  | 
|  | 
 
| voiL 中级用户
 
    
 
 
 
 积分 384
 发帖 189
 注册 2005-10-19
 状态 离线
 | 
| 『第 5 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
没有中文的说明,只能看懂一部分. 
There is no Chinese explanation, and I can only understand part of it. 
 
 
 |  | 
|  2006-7-27 00:10 |  | 
|  | 
 
| IceCrack 中级用户
 
    DOS之友
 
 
 积分 332
 发帖 168
 注册 2005-10-6
 来自 天涯
 状态 离线
 | 
| 『第 6 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
英文单词不是太多啊.不认识的可以用百度词典查一下的.而且批处理不会的话.应该把哪个不会说出来.这样也好解释.如果你全篇看不懂的话.那么你不适合看这篇文章.可以看一下我签名中的这个电子书.应该对你有帮助的 
The number of English words is not too many. If you don't know, you can check it with Baidu Dictionary. Also, if you don't know batch processing, you should mention which part you don't understand. That way it's easier to explain. If you can't understand the whole passage, then you may not be suitable for reading this article. You can take a look at this e-book in my signature. It should be helpful to you. 
 
 
 
 |  
                  |  测试环境: windows xp pro sp2    高手是这样炼成的:C:\WINDOWS\Help\ntcmds.chm
 |  | 
|  2006-7-27 00:52 |  | 
|  | 
 
| qwr123 新手上路
 
  
 
 
 
 积分 14
 发帖 5
 注册 2006-7-26
 状态 离线
 |  | 
|  2006-7-27 11:50 |  | 
|  | 
 
| Climbing 铂金会员
 
        网络独行侠
 
 
 积分 6962
 发帖 2753
 注册 2003-4-16
 来自 河北保定
 状态 离线
 | 
| 『第 8 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
很不错,以前还真没有注意到more命令有那么多的参数。 
It's pretty good. I really didn't notice before that the more command has so many parameters. 
 
 
 
 |  
                  |  偶只喜欢回答那些标题和描述都很清晰的帖子!
 如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
 
 |  | 
|  2006-7-27 14:50 |  | 
|  | 
 
| namejm 荣誉版主
 
        batch fan
 
 
 积分 5226
 发帖 1737
 注册 2006-3-10
 来自 成都
 状态 离线
 | 
| 『第 9 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
  more的用法真是强。以后要显示指定行的内容就有模式可套用了,呵呵,不错不错。 
The usage of more is really powerful. In the future, there will be a pattern to follow when displaying the content of specified lines. Hehe, not bad, not bad. 
 
 
 
 |  
                  |  尺有所短,寸有所长,学好CMD没商量。
 考虑问题复杂化,解决问题简洁化。
 |  | 
|  2006-7-27 18:51 |  | 
|  | 
 
| hxuan999 中级用户
 
    DOS之日
 
 
 积分 337
 发帖 161
 注册 2006-11-4
 状态 离线
 | 
| 『第 10 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
有点乱 
 
 
 
 
 |  
                  |  for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul
 |  | 
|  2006-11-23 03:33 |  | 
|  | 
 
| redtek 金牌会员
 
       
 
 
 
 积分 2902
 发帖 1147
 注册 2006-9-21
 状态 离线
 | 
| 『第 11 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by namejm at 2006-7-27 05:51:more的用法真是强。以后要显示指定行的内容就有模式可套用了,呵呵,不错不错。
 
同感,无限佩服~:) 
好玩的贴子不能沉下去~:) 
Originally posted by namejm at 2006-7-27 05:51:The usage of more is really powerful. In the future, there will be a pattern to apply when displaying the content of a specified line. Hehe, not bad not bad.
 
I feel the same way, extremely admiring~:) 
Fun posts shouldn't sink~:) 
 
 
 
 |  
                  |  Redtek,一个永远在网上流浪的人……
 
 _.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
 |  | 
|  2006-11-25 03:19 |  | 
|  | 
 
| foxfast 新手上路
 
  
 
 
 
 积分 14
 发帖 6
 注册 2007-1-12
 状态 离线
 | 
| 『第 12 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
真的很晕,签名里从÷的路径是错了的啊 
Really confused, the path from ÷ in the signature is wrong 
 
 
 |  | 
|  2007-1-15 03:51 |  | 
|  | 
 
| xiaohacker 初级用户
 
   
 
 
 积分 110
 发帖 45
 注册 2007-1-7
 状态 离线
 | 
| 『第 13 楼』:
 佩服的五体投地
 
使用 LLM 解释/回答一下 
 
 
强人,我佩服的五体投地,但是没有中文说明,我是看的一塌糊涂!唉,请高手们指点一下我等菜们应该看一些什么样的dos技术书! 
Great people, I admire them completely, but there are no Chinese explanations, and I'm completely confused! Alas, please experts guide us novices what kind of DOS technical books we should read! 
 
 
 |  | 
|  2007-1-15 05:30 |  | 
|  | 
 
| ccwan 金牌会员
 
       
 
 
 积分 2725
 发帖 1160
 注册 2006-9-23
 来自 河北廊坊
 状态 离线
 | 
| 『第 14 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
灌水
 Last edited by ccwan on 2007-1-20 at 09:24 PM ]
 
Flood
 Last edited by ccwan on 2007-1-20 at 09:24 PM ]
 
 
 
 
 |  
                  |  三人行,必有吾师焉。   学然后知不足,教然后知困,然后能自强也。
 |  | 
|  2007-1-15 06:30 |  | 
|  | 
 
| 40szb 初级用户
 
   
 
 
 
 积分 46
 发帖 21
 注册 2006-12-25
 来自 西安
 状态 离线
 |  | 
|  2007-1-21 09:55 |  |