Even after deep Googeling I can't solve my problem. Have a text file named test.txt. What I need is to change the line starts with the word "Root:" with other content - using batch file.
setLocal EnableDelayedExpansion
FINDSTR /B Root: test.txt
::returns the correct line - works well
for /f %%i in ('FINDSTR /B Root: test.txt') do set root=%%i
echo %root%
::echos "Root:" - instead of the line content
FOR /F "tokens=*" %%G IN (test.txt) DO
(set x=%%G
if !x!==%root% set x=Hello
echo !x! >> test.txt)
::The syntax of the command is incorrect.
How do i can do it?
EDIT: Based on Magoo and on RobW at Batch / Find And Edit Lines in TXT file - my problem solved as below:
for /f "tokens=*" %%i in ('"FINDSTR /B Root: test.txt"') do set root=%%i
::root holds test.txt's line starts with "Root:"
echo %root%
SETLOCAL=ENABLEDELAYEDEXPANSION
::iterate on test.txt's lines and compare to the root's value
rename test.txt test.tmp
for /f "tokens=*" %%a in (test.tmp) do (
set foo=%%a
echo !foo!
echo %root%
echo "%root%"
if "!foo!"=="%root%" (set foo=hello)
echo !foo! >> test.txt)
del test.tmp
Thanks! Roni