好的,这里有一个文件txt.txt
line1
line2
add after this line
line4
etc
etc
和另一个addthis.txt
包含多行的文件
我想在 addthis 之后添加所有这些行add after this line
我想知道的是我必须在这方面做出哪些改变才能完成它??
任何帮助深表感谢。
@ECHO OFF
SETLOCAL
SET /p info="enter info : "
:: read addafter line
(
FOR /f "delims=" %%i IN (poison1.txt) DO (
SET addafter=%%i
FOR /f "delims=" %%n IN (' findstr /n "^" txtfile.txt') DO (
SET line=%%n
SETLOCAL ENABLEDELAYEDEXPANSION
SET line=!line:*:=!
ECHO(!line!
IF "!line!"=="!addafter!" TYPE your_multiline_addition.txt
ENDLOCAL
)
)
)>newfile.txt
FC newfile.txt txtfile.txt
GOTO :eof
只需要TYPE your_multiline_addition.txt
而不是ECHO(%input%
(你也可以扔掉你的输入)
或者
你可以
TYPE "%info%"
如果您想输入包含附加内容的文件的名称
测试数据和结果:
======== poison1.txt ===========
"A line !of! ] many < & >var*ied %poison ^ char;ac(ters) | like "," a\nd+so=on"
======== extra_lines.txt ===========
extra line one
extra line two
extra line three
======== txtfile.txt ===========
line one
line two
line three
A line !of! ] many < & >var*ied %poison ^ char;ac(ters) | like "," a\nd+so=on
line 5 was blank - this is line FIVE
"A line !of! ] many < & >var*ied %poison ^ char;ac(ters) | like "," a\nd+so=on"
line 8 was blank - this is line NINE
======== newfile.txt ===========
line one
line two
line three
A line !of! ] many < & >var*ied %poison ^ char;ac(ters) | like "," a\nd+so=on
line 5 was blank - this is line FIVE
"A line !of! ] many < & >var*ied %poison ^ char;ac(ters) | like "," a\nd+so=on"
extra line one
extra line two
extra line three
line 8 was blank - this is line NINE