|
本帖最后由 dos时代菜鸟 于 2021-11-2 22:04 编辑
如下代码,把str1.txt 简化生成为 str2.txt
算法,把文件第一行赋值给变量并计算长度,然后进行第二行,如果第二行前面指定长度的内容与上面那个赋值一样,就跳过,反之重复赋值计算长度,再来。以此类推。
- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- set file1="str1.txt"
- set file2="str2.txt"
- echo.>!file2!
- call :text_1
- pause
- goto :eof
- :text_1
- set t=0
- set "l0="
- set l1=1
- for /f "delims=" %%i IN ('type %file1%') do (
- set /a t=!t!+1
- set L2=%%i
- call :str_L "%%i"
- for %%r in (!L1!) do (
- if not "!l2:~0,%%r!"=="!L0!" (
- set L1=!x!
- set L0=%%i
- echo !t!:%%i
- echo %%i >>!file2!
- )
- )
- )
- exit /b
- :str_L
- SET "L=%~1"
- SET /A N=0,M=8190 ,X=0
- FOR /L %%C IN (1,1,14) DO (
- SET /A X0=%X%
- SET /A "X=(!M!+!N!)/2+1"
- FOR /F %%D IN ("!X!") DO (
- IF "!L:~%%D!" EQU "" (SET /A M=!X! ) ELSE (SET /A N=!X!)
- )
- )
- exit /b
-
复制代码
str1.7z
(630 Bytes, 下载次数: 5)
|
|