3 回答

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊
這是一個(gè)通用批處理文件,用于打印nGNU head實(shí)用程序之類的文件中的頂行,而不僅僅是一行。
@echo off
if [%1] == [] goto usage
if [%2] == [] goto usage
call :print_head %1 %2
goto :eof
REM
REM print_head
REM Prints the first non-blank %1 lines in the file %2.
REM
:print_head
setlocal EnableDelayedExpansion
set /a counter=0
for /f ^"usebackq^ eol^=^
^ delims^=^" %%a in (%2) do (
if "!counter!"=="%1" goto :eof
echo %%a
set /a counter+=1
)
goto :eof
:usage
echo Usage: head.bat COUNT FILENAME
例如:
Z:\>head 1 "test file.c"
; this is line 1
Z:\>head 3 "test file.c"
; this is line 1
this is line 2
line 3 right here
當(dāng)前不計(jì)算空白行。它也受批處理文件行長(zhǎng)度限制為8 KB。

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
呃你們...
C:\>findstr /n . c:\boot.ini | findstr ^1:
1:[boot loader]
C:\>findstr /n . c:\boot.ini | findstr ^3:
3:default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
C:\>

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以嘗試一下:
@echo off
for /f %%a in (sample.txt) do (
echo %%a
exit /b
)
編輯 或者,假設(shè)您有四列數(shù)據(jù),并且想要從第5行到底部,請(qǐng)嘗試以下操作:
@echo off
for /f "skip=4 tokens=1-4" %%a in (junkl.txt) do (
echo %%a %%b %%c %%d
)
- 3 回答
- 0 關(guān)注
- 4066 瀏覽
添加回答
舉報(bào)