就原文本来解答- @echo off&setlocal enabledelayedexpansion
- set "tab=#"&rem 把左边的#号替换为 tab 键
- for /f "delims=" %%a in (ss.txt) do (
- set "str=%%a"
- set "str=!str:%tab%%tab%%tab%%tab%=%tab%0%tab%0%tab%0%tab%!"
- set "str=!str:%tab%%tab%%tab%=%tab%0%tab%0%tab%!"
- set "str=!str:%tab%%tab%=%tab%0%tab%!"
- if "!str:~-1!"=="%tab%" set "str=!str:~0,-1!%tab%0"
- echo !str!
- )
- pause
复制代码 从第一行中提取总列数- @echo off&setlocal enabledelayedexpansion
- set "tab= #"&rem 把左边的#号替换为 tab 键
- set /p var=<ss.txt
- for %%a in (!var!) do (
- set /a n+=1
- for /l %%i in (1 1 !N!) do set t=!t!%tab%&set tt=!tt!%tab%0
- set t!n!=!t!&set t!n!!n!=!tt:~0,-1!
- set t=&set "tt="
- )
- set /a n-=1
- for /f "delims=" %%a in (ss.txt) do (
- set "str=%%a"
- for /l %%i in (!n! -1 2) do (
- for /f "tokens=1,2 delims=/" %%j in ("!t%%i!/!t%%i%%i!") do (
- set "str=!str:%%j=%%k!"
- ))
- if "!str:~-1!"=="%tab%" set "str=!str:~0,-1!%tab%0"
- echo !str!
- )
- pause
复制代码
|