算字节长度其实也可以将文本转换为16进制字串进行计算和处理,而且不用担心任何特殊字符。- @echo off&setlocal enabledelayedexpansion
- set "input=a.txt"&set /a m=line=1&set "act=set/p=,&set/a m=1"
- for %%i in ("%input%") do fsutil file creATenew "%input%.zero" %%~zi >nul
- (for /f "tokens=2" %%a in ('fc /b "%input%" "%input%.zero"^|findstr /irc:"[0-9A-F]*: [0-9A-F][0-9A-F] 00"') do (
- if /i "%%a"=="0A" (echo,&set/a m=1,line+=1,col=0) else if /i "%%a"=="0D" (echo,
- for %%l in (!line!) do for /l %%i in (1,1,!col!) do (
- if !C%%i_%%l! gtr !C%%imax! set/a C%%imax=C%%i_%%l
- set "C%%i_%%l="
- ) ) else if /i "%%a"=="20" (%act%) else if /i "%%a"=="09" (%act%) else (
- set/p=%%a
- set /a col+=m,m=0
- set /a C!col!_!line!+=1
- )
- ))<nul >"%input%.temp"
- (for /f "delims=" %%a in (%input%.temp) do (
- set /a col=0
- for %%i in (%%a) do (
- set /a col+=1&set "space="
- set /a size=C!col!max,len=size*2+2
- for /l %%i in (1,1,!size!) do set "space=!space!20"
- set "outstr=%%i!space!"
- for %%i in (!len!) do echo,!outstr:~0,%%i!
- )
- set /p =0d0a
- ) )<nul >"out_%input%"
- del /q "%input%.zero" "%input%.temp"
- certutil -decodehex -f "out_%input%" "out_%input%" >nul
- pause
复制代码
|