加上多余的/o开关会影响效率的吧?
其它几种方法:- @echo off
- for /f "tokens=1 delims=:" %%a in ('findstr /n .* a.txt') do (
- set RowNum=%%a
- )
- echo %RowNum%
- rem 10万行文本的测试结果:3分14.46秒
- rem 15:45:22.25
- rem 100000
- rem 15:48:36.71
复制代码
- @echo off
- for /f "tokens=2 delims=:" %%a in ('find /v /c "" a.txt') do (
- set "RowNum=%%a"
- goto :print
- )
- :print
- set "RowNum=%RowNum: =%"
- echo %RowNum%
- rem 10万行文本的测试结果:8.95秒
- rem 15:54:04.05
- rem 100000
- rem 15:54:13.00
复制代码
- @echo off
- for /f %%a in (a.txt) do (
- set /a RowNum+=1
- )
- echo,%RowNum%
- rem 10万行文本的测试结果:5.20秒
- rem 15:51:30.55
- rem 100000
- rem 15:51:35.75
复制代码
- @echo off
- for /f %%a in ('type a.txt ^| find /c /v ""') do (
- set "RowNum=%%a"
- )
- echo,%RowNum%
- rem 10万行文本的测试结果:2.92秒
- rem 15:57:54.64
- rem 100000
- rem 15:57:57.56
复制代码
|