在txtfile中间添加多行 [英] add multiple lines in middle of txtfile
问题描述
ok
这里是一个档案 txt.txt
line1
line2
在此行后添加
line4
etc
etc
和另一个文件 addthis.txt
其中包含多行
我想添加所有这些行在addthis后添加后这行
我想知道的是什么所有更改都必须在此中完成
<$ p $
$ @ECHO OFF
SETLOCAL
SET / p info =enter info:
:: read addafter line
(
FOR / fdelims =%% i IN(poison1.txt)DO(
SET addafter = %% i
FOR / fdelims =%% n IN('findstr / n^txtfile .txt')DO(
SET line = %% n
SETLOCAL ENABLEDELAYEDEXPANSION
SET line =!line:*:=!
ECHO(!line!
!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%
如果您要输入包含附加功能的文件名称
测试数据和结果: / p>
======== poison1.txt ===========
一行!! ]& &安培; > var * ied%poison ^ char; ac(ters)| like,a\\\
d + so = on
======== extra_lines.txt ===========
extra line one
第二行
第三行
======== txtfile.txt ===========
第一行
第二行
line three
一行!of!] many<&> var * ied%poison ^ char; ac(ters)| like,a\\\
d + so = on
第5行是空白的 - 这是第FIVE
A行! ]& &安培; > var * ied%poison ^ char; ac(ters)| like,a \\\
d + so = on
第8行为空白 - 这是第NINE
======== newfile.txt ===== ======
line one
line two
line three
一行!of many]<&> var * ied%poison ^ char; ac (ters)| like,a \\\
d + so = on
第5行为空 - 这是行FIVE
A行! ]& &安培; > var * ied%poison ^ char; ac(ters)| like,a \\\
d + so = on
extra line one
extra line 2
extra line 3
第8行为空 - 这是行NINE
ok
here a file txt.txt
line1
line2
add after this line
line4
etc
etc
and another file addthis.txt
which contains multiple lines
i want to add all those lines in addthis after add after this line
what i want to know is what all changes i have to make in this to accomplish it??
any help is much appreciated.
@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
Just need to TYPE your_multiline_addition.txt
rather than ECHO(%input%
(and you can probably toss away your input, too)
OR
you could
TYPE "%info%"
if you want to enter the name of the file containing the extras
Test data and Results:
======== 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
这篇关于在txtfile中间添加多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!