这是一个通用批处理文件,用于打印nGNU head实用程序之类的文件中的顶行,而不仅仅是一行。@echo offif [%1] == [] goto usageif [%2] == [] goto usagecall :print_head %1 %2goto :eofREMREM print_headREM Prints the first non-blank %1 lines in the file %2.REM:print_headsetlocal EnableDelayedExpansionset /a counter=0for /f ^"usebackq^ eol^=^^ delims^=^" %%a in (%2) do ( if "!counter!"=="%1" goto :eof echo %%a set /a counter+=1)goto :eof:usageecho Usage: head.bat COUNT FILENAME例如:Z:\>head 1 "test file.c"; this is line 1Z:\>head 3 "test file.c"; this is line 1 this is line 2line 3 right here当前不计算空白行。它也受批处理文件行长度限制为8 KB。