)
set "lines=3"
set start=5
if !i!==%lines% set ok=1
if not defined ok echo/%%a @echo off JT_man注:或 pause>nul if "!i!"=="%lines%" set ok=1 ------------------------123_2.bat------------------------------- setlocal enabledelayedexpansion @echo off pause>nul setlocal enabledelayedexpansion set "lines=2" for /f "delims=" %%a in ('more ^< numbers.txt') do ( 文章標籤
set
delims
echo
bat
txt
nul
command
setlocal ENABLEEXTENSIONS >>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: ------------------------通用.bat-------------------------------------------------- set /a i+=1 JT_man注:或 ------------------------123_2.bat------------------------------- set/a i=-1,start-=1 set "ok=" ) |
set i=-1
從文字檔中讀取特定的行
for /f "skip=%start% delims=" %%a in ('more ^< numbers.txt') do (
rem 顯示前3行
rem 入手下手顯示的行號
set/a i+=1
------------------------通用.bat--------------------------------------------------
rem 要顯示的行數
>>Displaying the last line翻譯社This example prints ten.
顯示最後一行,列印第十行的例子如下:
------------------------10.bat--------------------------------------------
@echo off & setlocal ENABLEEXTENSIONS
for /f "delims=" %%a in ('more ^< numbers.txt') do set "last=%%a"
echo/%last%
pause>nul
------------------------10.bat--------------------------------------------
>>Displaying the last X lines,This example prints nine and ten.
顯示最後x行,列印第9,10行的例子以下:
------------------------lastx.bat-----------------------------------------------
@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 (
:: 或 for /f "skip=%skip% delims=" %%a in ('more ^< numbers.txt') do (
echo/%%a
)
pause>nul
------------------------lastx.bat------------------------------------------------
>>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.
顯示第n行,列印第三行.
注意啟用more命令的擴大功能(/e)開關,同時,ship選項曩昔常用於for /f定名中翻譯社然則當設定的數目小於現實值時,將致使失敗
------------------------Nth.bat-----------------------------------------------
@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%
pause>nul
------------------------Nth.bat------------------------------------------------
>>Displaying the Nth line plus X number of lines,This example prints five and six.
顯示第n+x行,列印第5,6行的例子以下:
------------------------x+Nth.bat--------------------------------------------------
@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
)
pause>nul
------------------------x+Nth.bat----------------------------------------------------
set "ok="
if not defined ok echo %%a
文章來自: http://johnson560.pixnet.net/blog/post/311855304-%E5%BE%9E%E6%96%87%E5%AD%97%E6%AA%94%E4%B8%AD%E8%AE有關各國語文翻譯公證的問題歡迎諮詢華頓翻譯公司02-77260932