[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] [已解决]请教批处理高效统计文本行数

本帖最后由 kkfgef 于 2015-11-19 10:23 编辑
  1. @echo off&setlocal enabledelayedexpansion
  2. echo;计时开始(%time:~,8%)
  3. for /f "delims=" %%a in ('dir /a-d/b/s *.txt') do (
  4.   for /f "tokens=3 delims=:" %%b in ('find /c /v "" "%%a"') do set n=%%b
  5.   echo;"文本%%~na%%~xa有!n: =!行">>hangsu.log
  6. )
  7. echo;计时结束(%time:~,8%)
  8. pause
复制代码
这个一秒只能处理几个文本而已,每个才一千行左右……
文件夹中两万个,要统计到什么时候哟
如何更高效快速统计呢
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

空行算不算数?
挂机慢慢跑呗。
下载安装python3 https://www.python.org/downloads/ 代码存为xx.py 双击运行或IDLE打开F5运行

TOP

本帖最后由 依山居 于 2015-11-17 14:21 编辑

wc 统计行数

http://batch-cn.qiniudn.com/s/tool/index.html
  1. o( ̄▽ ̄)o 2015/11/17 周二14:19:32.75 <( ̄︶ ̄)>
  2. c:\>wc t.txt
  3.       1       1       7 t.txt
  4. o( ̄▽ ̄)o 2015/11/17 周二14:20:34.03 <( ̄︶ ̄)>
  5. c:\>wc --help
  6. Usage: wc [OPTION]... [FILE]...
  7. Print byte, word, and newline counts for each FILE, and a total line if
  8. more than one FILE is specified.  With no FILE, or when FILE is -,
  9. read standard input.
  10.   -c, --bytes            print the byte counts
  11.   -m, --chars            print the character counts
  12.   -l, --lines            print the newline counts
  13.   -L, --max-line-length  print the length of the longest line
  14.   -w, --words            print the word counts
  15.       --help     display this help and exit
  16.       --version  output version information and exit
  17. Report bugs to <bug-textutils@gnu.org>.
复制代码
1

评分人数

下载安装python3 https://www.python.org/downloads/ 代码存为xx.py 双击运行或IDLE打开F5运行

TOP

  1. find /c /v <a.txt
复制代码
  1. sed -n "$=" *.txt
复制代码
  1. gawk "{n=NF}END{print NF?NF:0}" a.txt
复制代码
1

评分人数

TOP


f 或者FR也可以 http://baiy.cn/utils/f/index.htm
  1. c:\>f -ric:\n -fmc t.txt
  2. t.txt:2:
复制代码
1

评分人数

下载安装python3 https://www.python.org/downloads/ 代码存为xx.py 双击运行或IDLE打开F5运行

TOP

回复 1# kkfgef


这样应该可以提高一些效率:
  1. @echo off
  2. echo;计时开始(%time:~,8%)
  3. (for /f "delims=" %%a in ('dir /a-d /b *.txt') do (
  4.     for /f %%b in ('type "%%a" ^| find /c /v ""') do (
  5.         echo;"文本%%~nxa有%%b行"
  6.     )
  7. ))>hangsu.log
  8. echo;计时结束(%time:~,8%)
  9. pause
复制代码
1

评分人数

TOP

  1. c:\>f -r:\n   t.txt -o  -fmc
  2. ## 15 matchs in file.
复制代码
空行只有回车换行的不计数。
1

评分人数

下载安装python3 https://www.python.org/downloads/ 代码存为xx.py 双击运行或IDLE打开F5运行

TOP

  1. @echo off
  2. for /f "tokens=*delims=- " %%i in ('find /c /v  "" *.txt') do (
  3.     echo %%i 行
  4. )
  5. pause
复制代码
1

评分人数

TOP

返回列表