權狀翻譯推薦翻譯社

從文字檔中讀取特定的行

      set/a i+=1

setlocal enabledelayedexpansion

set "ok=" 

------------------------通用.bat-------------------------------------------------- 

)

rem 要顯示的行數

------------------------123_2.bat------------------------------- 

JT_man注:或

setlocal ENABLEEXTENSIONS 
set "first=" 
for /f "delims=" %%a in ('more ^< numbers.txt') do ( 
if not defined first set first=%%a 

echo/%first% 
pause>nul 
------------------------1.bat-------------------------------------------

>>Displaying the first X lines,This example prints one, two and three. 
顯示前幾行,列印第一翻譯社二,三行的例子以下: 
------------------------123.bat------------------------------- 
@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 

pause>nul 
------------------------123.bat-------------------------------

set i=-1  

------------------------123_2.bat------------------------------- 

for /f "skip=%start% delims=" %%a in ('more ^< numbers.txt') do (

@echo off

set start=5

rem 顯示前3行

>>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 delims echo bat txt nul command

@echo off

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----------------------------------------------------

for /f "delims=" %%a in ('more ^< numbers.txt') do (

set "ok="

set "lines=2"

      if not defined ok echo/%%a

      set /a i+=1

      if "!i!"=="%lines%" set ok=1

pause>nul 

pause>nul 

set "lines=3"

      if not defined ok echo %%a

set/a i=-1,start-=1

setlocal enabledelayedexpansion

JT_man注:或者

------------------------通用.bat-------------------------------------------------- 

      if !i!==%lines% set ok=1



本篇文章引用自此: 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

文章標籤
全站熱搜
創作者介紹
創作者 chavezw15462 的頭像
chavezw15462

chavezw15462@outlook.com

chavezw15462 發表在 痞客邦 留言(0) 人氣(50)