pause>nul
if not defined ok echo %%a
if "!i!"=="%lines%" set ok=1
------------------------通用.bat--------------------------------------------------
從文字檔中讀取特定的行
set i=-1
rem 要顯示的行數
------------------------通用.bat--------------------------------------------------
)
if not defined ok echo/%%a
@echo off
for /f "skip=%start% delims=" %%a in ('more ^< numbers.txt') do (
>>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敕令的多種轉變體例可以達到該目標,例如:
---------------------------------for /f-----------------------------------------
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 ...
---------------------------------for /f-----------------------------------------
>>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).
但是,只有最後一種方法(用到more敕令的)在windows nt,2000,xp和2003中可以或許獲得一致的結果翻譯第一種方式,不克不及有效的辨認unicode編碼檔翻譯社同時翻譯社若是檔案名含有空格時,usebackq開關必需打開。第二種方法翻譯社用到type敕令,一樣在windows nt,2000,xp和2003中,不克不及有效辨認unicode編碼檔,同時,要求輸入的檔內容不克不及以位元序標誌(BOM)開首.
>>In all the examples翻譯社 assume the contents of of the file numbers.txt to be:
在如下所有的例子中,假定numbers.txt檔輸入以下內容:
----------------------numbers.txt--------------------------
one
two
three
four
five
six
seven
eight
nine
ten
----------------------numbers.txt--------------------------
JT_man注:以下代碼中的setlocal ENABLEEXTENSIONS都可以刪除,因為系統預設號令處置器副檔名是啟動的。
>>Displaying the first line翻譯社This example prints one.
顯示第一行翻譯社列印第一行的例子如下:
------------------------1.bat------------------------------------------
@echo off &
set "ok="
set/a i=-1,start-=1
set "lines=3"
rem 開始顯示的行號
------------------------123_2.bat-------------------------------
if !i!==%lines% set ok=1
set/a i+=1
JT_man注:或
|
rem 顯示前3行 set "lines=2" @echo off setlocal enabledelayedexpansion setlocal ENABLEEXTENSIONS for /f "delims=" %%a in ('more ^< numbers.txt') do ( set "ok=" ------------------------123_2.bat------------------------------- ) setlocal enabledelayedexpansion set start=5 JT_man注:或 >>Displaying the last line,This example prints ten. |
set /a i+=1
pause>nul
以下文章來自: 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-77260931
請先 登入 以發表留言。