【发布时间】:2022-01-20 08:00:48
【问题描述】:
我有以下代码
@echo off
setlocal enableextensions disabledelayedexpansion
set "search=hello"
set "replace=hello world"
set "textFile=hello.text"
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%textFile%" echo(!line:%search%=%replace%!
endlocal
)
如何使用此脚本在 Hello 和 world 之间添加换行符
我的 hello.txt 包含以下内容:
def a=1
config{
hello
}
我想换成
def a=1
config{
hello
world
}
主要目的是在下一行的hello之后添加world
【问题讨论】:
-
这取决于,你想为所有用换行符分隔的单词添加换行符吗?还是仅在“Hello World”事件中?
-
仅在 Hello World 事件中
标签: windows batch-file