用脚本,或者批处理实现:删除一文本中每行最后得一个字符,在每行的开头插入一个字符

2024-12-31 03:25:11
推荐回答(3个)
回答1:

@echo off&setlocal enabledelayedexpansion
set/p .=输入插入前面的字符:
for /f "tokens=1,* delims=:" %%a in ('findstr /n .* 1.txt')do (
if "%%b"=="" (echo.>>#1#.txt
) else (
set var=%%b
set var=%.%!var:~0,-1!
echo=!var!>>#1#.txt
))
pause

#1#.txt就是你要的文本.

回答2:

@setlocal ENABLEDELAYEDEXPANSION
set "a=开关要加的字符"
for /f "delims=" %%a in (1.txt) do echo %a%%%a>>2.txt
for /f "delims=" %%a in (2.txt) do set b=%%a&echo !b:~0,-1!>>3.txt
del 2.txt /q
pause

回答3:

mggdx 没写完整。
补全。
@echo off&setlocal ENABLEDELAYEDEXPANSION
if exist 3.txt del 3.txt /q
set /p x=开关要加的字符
for /f "delims=" %%a in (1.txt) do echo %x%%%a>>2.txt
for /f "delims=" %%i in (2.txt) do set b=%%i&echo !b:~0,-1!>>3.txt
del 2.txt /q
start "" 3.txt
pause

这比较好理解