编程在文本中特定地方插入空行

2025-12-13 02:24:35
推荐回答(1个)
回答1:

@echo off&&setlocal enabledelayedexpansion
:start
cls
if not exist 示例.txt echo 同级目录下不存在“示例.txt”。&&pause>nul&&goto :eof
echo 1、输出空行
echo 2、删除特征行
set /p num=请输入您的选择:
if "!num!"=="1" goto echonull
if "!num!"=="2" (goto delword) else (echo 选择有误,请重新选择。&&pause>nul&&goto start)
:echonull
call :delit
call :setword
for /f "delims=" %%a in (示例.txt) do (
set str=%%a
if "!str:~0,1!"=="!word!" (call :kong1) else (set strall=!str!%%a&&echo !str!)
)>>2.txt
start 2.txt
echo 操作完毕,请检查。&&pause>nul&&goto start
:kong1
call :kong2
echo !str!
call :kong2
goto :eof
:kong2
for /l %%i in (1,1,8) do (
echo.
)
goto :eof
:delword
call :delit
call :setword
for /f "delims=" %%a in (示例.txt) do (
set str=%%a
if "!str:~0,1!" neq "!word!" (echo !str!)
)>>2.txt
start 2.txt
echo 操作完毕,请检查。&&pause>nul&&goto start
:setword
set /p word=请输入特征字符:
goto :eof
:delit
if exist 2.txt del 2.txt/f/q

::另存为oo.bat,和有问题百度HI我