bat替换指定行的内容中,指定的字符串

比如说:
11,aa
22,aa
33,bb
44,aa

我只想将第一行的aa替换为“haha”,第二行和第四行的都不替换

或者可以这样解释,文件中,有多个指定的字符串,我只要替换第一个,其他的不替换

@echo off&setlocal enabledelayedexpansion
set "s=aa"
set "d=haha"
(for /f "delims=" %%a in (1.txt) do (
    set "str=%%a"
    if not defined a (
     if not "!str:%s%=!"=="%%a" (
         set str=!str:%s%=%d%!
            set a=.
     )
    )
    echo,!str!
))>2.txt

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答