直到找到该行并用另一个文本文件windows批处理脚本替换 [英] Find until that line and replace with another text file windows batch script
问题描述
我试图写一个windows批处理脚本,它会搜索,直到
例子:
I am trying to write a windows batch script that it will search until
Example:
example1
example2
example3
example4
<jar href="example.jar" main="true"/>
所以我想替换第一部分直到(< jar href)
的文字与另一个文字。
我的意思是第一个4行将被替换为另一个文本。
批处理脚本中是否有直接找到和替换的方法?
So i want to replace first part until ( <jar href )
of the text with another text.
I mean the first the first 4 lines will be replaces with another text.
Is there any find until and replace method in batch script.
推荐答案
您的特定场景很容易批量实施。我假设你想保留整个包含< jar href
Your specific scenario is fairly easy to implement in batch. I'm assuming you want to preserve the entire line that contains <jar href
的行替换文本来自哪里。
You don't say where the replacement text is coming from. I'm assuming it comes from another file.
@echo off
set file1="test.txt"
set file2="replacement.txt"
set output="new.txt"
for /f "delims=:" %%N in ('findstr /n /c:"<jar href" %file1%') do (
set /a skip=%%N-1
goto :break
)
:break
(
type %file2%
more +%skip% %file1%
)>%output%
这篇关于直到找到该行并用另一个文本文件windows批处理脚本替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!