I have to replace a line within a txt with batch and I need help with the code ... I have the files test.txt and test2.txt the objective is to move from file 1 to file 2 with the same content unless it contains a specific word, in which case, the entire line must be replaced by a predefined one.
I specifically have problems with the 'if' and with the reassignment of the variable.
>@echo off
>setlocal enabledelayedexpansion
>set p1=prueba.txt
>set p2=prueba2.txt
>for /f "tokens=*" %%a in (%p1%) do (
> set nl=%%a
> if not "%n1%"=="%n1:texto=%" (
> set n1=este texto esta mejor
> )
> echo !n1! >> %p2%
>)
>pause>nul
>exit
Thank you very much for your help