0

我有一个文本文件,其中包含一些行

line1
line2
helloabcd
line4

我想创建一个批处理文件来编辑 helloabcd 行,%this%但我不知道abcd我所知道的是什么hello。那我该怎么做呢?

我尝试使用 fart.exe,但是当有通配符时它永远不会被替换

fart.exe txt1.txt hello* %this%

可以用纯cmd,甚至用放屁来完成吗?

提前感谢您的回复

编辑:好的尝试fart.exe txt1.txt hello %this%但现在我得到了%this%abcd而不是%this%

4

1 回答 1

1

试试这个:

@echo off &setlocal
set "this=wqreqwrq"
for /f "delims=" %%i in ('^<txt1.txt findstr /n "^"') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:*:=!"
    if not "!line!"=="!line:hello=!" set "line=%this%"
    (echo(!line!)>>output.txt
    endlocal
)

输出在output.txt.

编辑:添加。“!” 删除。

于 2013-05-04T15:24:48.010 回答