a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁(yè) > 編程 > BAT > 正文

批處理提取不同行上的內(nèi)容的代碼

2020-07-26 20:27:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
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
)
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美狠狠操 | 一区二区三区在线观看视频 | 国产 日韩 一区 | 国产精品成人久久久久 | 91.com在线观看 | av网站有哪些 | 四虎影视在线观看 | 蜜桃官网 | 成人免费视频在线观看 | 大胸av| 91最新视频| 久久九精品 | 亚洲国产精久久久久久久 | 成人精品| 欧美日韩精 | 黄色网址视频在线观看 | 午夜视频在线观看网站 | 久久久久久久久中文字幕 | 1级毛片 | 91精品国产欧美一区二区成人 | 成人毛片视频网站 | 国产福利电影在线观看 | 日韩欧美高清 | 久久91久久久久麻豆精品 | 日韩精品av一区二区三区 | 伊人小视频| 午夜国产羞羞视频免费网站 | 国外成人在线视频 | 亚洲www| 欧美日韩中文在线 | 国产精品欧美一区二区三区不卡 | 国产精品久久久久久久久久久新郎 | 午夜激情视频 | 成人午夜视频在线观看 | 深夜成人小视频 | 成人激情视频在线免费观看 | 青草青在线视频 | 天天干一干 | 国产精品久久一区 | 午夜国产羞羞视频免费网站 | 久久国产精品99久久久久久老狼 |