找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 29941|回复: 7

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

[复制链接]
发表于 2015-11-17 13:42:04 | 显示全部楼层 |阅读模式
本帖最后由 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
复制代码
这个一秒只能处理几个文本而已,每个才一千行左右……
文件夹中两万个,要统计到什么时候哟
如何更高效快速统计呢

评分

参与人数 1PB +2 收起 理由
Batcher + 2 感谢给帖子标题标注[已解决]字样

查看全部评分

发表于 2015-11-17 13:47:04 | 显示全部楼层
空行算不算数?
挂机慢慢跑呗。
发表于 2015-11-17 13:48:27 | 显示全部楼层
本帖最后由 依山居 于 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技术 +1 收起 理由
kkfgef + 1 谢谢

查看全部评分

发表于 2015-11-17 15:29:04 | 显示全部楼层
  1. find /c /v <a.txt
复制代码
  1. sed -n "$=" *.txt
复制代码
  1. gawk "{n=NF}END{print NF?NF:0}" a.txt
复制代码

评分

参与人数 1技术 +1 收起 理由
kkfgef + 1 谢谢

查看全部评分

发表于 2015-11-17 16:12:23 | 显示全部楼层

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

评分

参与人数 1技术 +1 收起 理由
kkfgef + 1 谢谢

查看全部评分

发表于 2015-11-17 16:31:55 | 显示全部楼层
回复 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技术 +1 收起 理由
kkfgef + 1 谢谢

查看全部评分

发表于 2015-11-17 16:32:03 | 显示全部楼层
  1. c:\>f -r:\n   t.txt -o  -fmc

  2. ## 15 matchs in file.
复制代码
空行只有回车换行的不计数。

评分

参与人数 1技术 +1 收起 理由
kkfgef + 1 谢谢

查看全部评分

发表于 2015-11-17 16:57:38 | 显示全部楼层
  1. @echo off
  2. for /f "tokens=*delims=- " %%i in ('find /c /v  "" *.txt') do (
  3.     echo %%i 行
  4. )
  5. pause
复制代码

评分

参与人数 1技术 +1 收起 理由
kkfgef + 1 谢谢

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-18 10:00 , Processed in 0.023872 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表