直接修改源文件,注意备份。
未考虑文件内容含!符号的情况。- @echo off&set /a flag=0,n=0
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in (a.txt) do (
- set /a n+=1
- set num=!num!%%i
- if !n! equ 2 (
- set /a n=0
- if !flag! equ 0 (
- set flag=2
- >a.txt echo !num:~0,-1!
- ) else (>>a.txt echo !num:~0,-1!)
- set "num="
- )
- )
- start a.txt
复制代码 第二个问题- @echo off&set /a flag=0,n=0
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in (a.txt) do (
- set /a n+=1
- set num=!num!%%i
- if !n! equ 2 (
- set /a n=1
- if !flag! equ 0 (
- set flag=2
- >a.txt echo !num:~0,-1!
- ) else (>>a.txt echo !num:~0,-1!)
- set "num=%%i"
- )
- )
- start a.txt
复制代码
|