Board logo

标题: [文本处理] 批处理命令findstr和find处理最大长度上限几例 [打印本页]

作者: ShowCode    时间: 2023-11-7 18:21     标题: 批处理命令findstr和find处理最大长度上限几例

测试环境

Win7: 6.1.7601
Win10: 10.0.19045.3570
Win11: 10.0.22621.2283
  1. @echo off
  2. REM 生成单行超长的文本文件
  3. echo "en8190.txt"
  4. (for /l %%i in (1,1,8190) do (
  5.     set /p =A<nul
  6. ))>"en8190.txt"
  7. echo,>>"en8190.txt"
  8. echo "en8191.txt"
  9. (for /l %%i in (1,1,8191) do (
  10.     set /p =A<nul
  11. ))>"en8191.txt"
  12. echo,>>"en8191.txt"
  13. echo "en1000000.txt"
  14. (for /l %%i in (1,1,1000000) do (
  15.     set /p =A<nul
  16. ))>"en1000000.txt"
  17. echo,>>"en1000000.txt"
  18. echo "cn4095.txt"
  19. (for /l %%i in (1,1,4095) do (
  20.     set /p =中<nul
  21. ))>"cn4095.txt"
  22. echo,>>"cn4095.txt"
  23. echo "cn4096.txt"
  24. (for /l %%i in (1,1,4096) do (
  25.     set /p =中<nul
  26. ))>"cn4096.txt"
  27. echo,>>"cn4096.txt"
  28. echo "cn1000000.txt"
  29. (for /l %%i in (1,1,1000000) do (
  30.     set /p =中<nul
  31. ))>"cn1000000.txt"
  32. echo,>>"cn1000000.txt"
复制代码

作者: ShowCode    时间: 2023-11-7 18:22

以下测试假设文本行尾都带有回车换行。文本行尾不带回车换行的情况,得出的结果会略有差异。
  1. REM findstr通过输入重定向输入获取数据,可以处理的单行最大长度为:
  2. REM 8190个英文或数字
  3. REM 4095个中文
  4. REM Win11系统上限未知
  5. findstr "A" < en8190.txt > en8190-s1.txt
  6. findstr "A" < en8191.txt > en8191-s1.txt
  7. findstr "中" < cn4095.txt > cn4095-s1.txt
  8. findstr "中" < cn4096.txt > cn4096-s1.txt
  9. REM 超出之后的报错信息为:FINDSTR: 行 1 太长。
  10. REM findstr通过管道获取数据,可以处理的单行最大长度为:
  11. REM 8190个单字节字符(英文或数字)
  12. REM 4095个双字节字符(中文)
  13. REM Win11系统上限未知
  14. type en8190.txt | findstr "A" > en8190-s2.txt
  15. type en8191.txt | findstr "A" > en8191-s2.txt
  16. type cn4095.txt | findstr "中" > cn4095-s2.txt
  17. type cn4096.txt | findstr "中" > cn4096-s2.txt
  18. REM 超出之后的报错信息为:FINDSTR: 行 1 太长。
  19. REM findstr直接从文件获取数据,尝试处理单行1000000的情况正常,不确定上限是多少
  20. findstr "A" en1000000.txt > en1000000-s0.txt
  21. findstr "中" cn1000000.txt > cn1000000-s0.txt
  22. REM find通过输入重定向输入获取数据,输出结果被截断至:
  23. REM 4095个单字节字符(英文或数字)
  24. REM 4095个双字节字符(中文)
  25. find "A" < en1000000.txt > en1000000-f1.txt
  26. find "中" < cn1000000.txt > cn1000000-f1.txt
  27. find "A" < en8190.txt > en8190-f1.txt
  28. find "中" < cn4096.txt > cn4096-f1.txt
  29. REM find通过管道获取数据,输出结果被截断至:
  30. REM 4095个单字节字符(英文或数字)
  31. REM 4095个双字节字符(中文)
  32. type en1000000.txt | find "A" > en1000000-f2.txt
  33. type cn1000000.txt | find "中" > cn1000000-f2.txt
  34. type en8190.txt | find "A" > en8190-f2.txt
  35. type cn4096.txt | find "中" > cn4096-f2.txt
  36. find "A" < en8190.txt > en8190-f1.txt
  37. find "中" < cn4096.txt > cn4096-f1.txt
  38. REM find直接从文件获取数据,输出结果被截断至:
  39. REM 4095个单字节字符(英文或数字)
  40. REM 4095个双字节字符(中文)
  41. find "A" en1000000.txt > en1000000-f0.txt
  42. find "中" cn1000000.txt > cn1000000-f0.txt
  43. find "A" en8190.txt > en8190-f0.txt
  44. find "中" cn4096.txt > cn4096-f0.txt
  45. REM findstr单个待查找关键字的最大长度为:
  46. REM 255个单字节字符(英文或数字)
  47. REM 127个双字节字符(中文)
  48. findstr "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" en8191.txt > en8191-s-p1.txt
  49. findstr "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" en8191.txt > en8191-s-p2.txt
  50. findstr "中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中" cn4095.txt > cn4095-s-p1.txt
  51. findstr "中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中" cn4095.txt > cn4095-s-p2.txt
  52. REM 超出之后的报错信息为:FINDSTR: 内存不足
  53. REM find单个待查找关键字的最大长度为:未知
  54. REM 只要整个命令不超过单行命令最大值8190即可
复制代码

作者: Five66    时间: 2023-11-7 23:11

win11这么强的???




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2