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

你要处理的文本存入 s.txt
  1. @echo off & setlocal enabledelayedexpansion
  2. chcp 936
  3. mode 200,1000
  4. set LN=^
  5. echo;[!LN!]
  6. >tmp.txt cd.
  7. for /f "delims=" %%a in (s.txt) do (
  8.     set "lin=%%a"
  9.     set "lin=!lin: =!"
  10.     echo !lin!
  11.     call :strlen lin length
  12.     echo !length!
  13.     call :output lin length
  14. )
  15. >sorted.txt sort tmp.txt
  16. >info.txt cd.
  17. set "last_distinct_line="
  18. set /a "cnt_duplicate=0,times_per_line=1"
  19. for /f "delims=" %%a in (sorted.txt) do (
  20.     if "%%a"=="!last_distinct_line!" (
  21.         set /a "times_per_line+=1"
  22.         if !times_per_line!==2 (
  23.             set /a cnt_duplicate+=1
  24.         )
  25.     ) else (
  26.         if "!last_distinct_line!" neq "" if !times_per_line! gtr 1 (
  27.             echo;!cnt_duplicate!,!times_per_line!:!last_distinct_line!
  28.             >>info.txt echo;!cnt_duplicate!,!times_per_line!:!last_distinct_line!
  29.         )
  30.         set "last_distinct_line=%%a"
  31.         set /a "times_per_line=1"
  32.     )
  33. )
  34. set cnt_duplicate
  35. pause
  36. exit
  37. :output
  38. setlocal enabledelayedexpansion
  39. set /a p=0
  40. :loop
  41.     set "out="
  42.     for /L %%i in (1 1 100) do (
  43.         if !p! lss !%2! for %%p in (!p!) do set "out=!out!!%1:~%%p,1!!LN!"
  44.         set /a p+=1
  45.     )
  46.     >>tmp.txt (echo;!out:~0,-1!)
  47. if !p! lss !%2! goto :loop
  48. endlocal
  49. exit /b
  50. :strlen <stringVarName> [retvar]
  51. :: 思路: 二分回溯联合查表法
  52. :: 说明: 所求字符串大小范围 0K ~ 8K;
  53. ::    stringVarName ---- 存放字符串的变量名
  54. ::    retvar      ---- 接收字符长度的变量名
  55. setlocal enabledelayedexpansion
  56. set "$=!%1!#"
  57. set N=&for %%a in (4096 2048 1024 512 256 128 64 32 16)do if !$:~%%a!. NEQ . set/aN+=%%a&set $=!$:~%%a!
  58. set $=!$!fedcba9876543210&set/aN+=0x!$:~16,1!
  59. endlocal&If %2. neq . (set/a%2=%N%)else echo %N%
  60. exit /b
复制代码

TOP

返回列表