本帖最后由 CrLf 于 2014-6-21 18:02 编辑
针对大文件:
batch- @echo off
- (for /l (9 -1) do set "line="&set/p line=)<a.txt
- echo %line%
复制代码 batch+js- @set @n=0;/*&echo off
- for /f "delims=" %%a in ('cscript -nologo -e:jscript %0 10 ^<a.txt') do set line=%%a
- if defined line echo %line%
- pause&exit/b
-
- */
- if(WSH.Arguments.length)
- for(i=WSH.Arguments(0);--i;)WSH.StdIn.SkipLine()
-
- if(!WSH.StdIn.AtEndOfStream)
- WSH.Echo(WSH.StdIn.ReadLine())
-
- WSH.Quit()
复制代码 sed复制代码 gawk- gawk "NR==10{print;exit}" a.txt
复制代码 perl- open(IN,'a.txt');
- print ((<IN>)[10]);
- close(IN);
复制代码 如果文件太大,写成这样更合理:- open(IN,'a.txt');
- foreach(<IN>){
- if($length++==10){print;break;}
- }
- close(IN);
复制代码 powershell- (Get-Content -TotalCount 10 a.txt)[-1]
复制代码
|