Solved removing a word from a text file?

May 9, 2014 at 14:02:47
Specs: Windows 7
SetLocal EnableDelayedExpansion
For /F "tokens=* delims=" %%A in (z.txt) Do (
Set TxtLine=%%A
Set TxtLine=!TxtLine:%var1%=!
echo !TxtLine!>>tmp.3)
del z.txt
rename tmp.3 z.txt

%var1% is b1.jpg.How can I alter the above code to make it remove a set variable from a text file. The above code currently only removes text from a file if I enter "b1.jpg" in place of %var1%


See More: removing a word from a text file?

Report •


#1
May 10, 2014 at 19:34:20
✔ Best Answer
set var1=
set /p var1=word:
if not defined var1 goto :eof
::------ implied "else": continue with replacement operation verbatim
For /F "tokens=* delims=" %%A in (z.txt) Do (
Set TxtLine=%%A
Set TxtLine=!TxtLine:%var1%=!
echo !TxtLine!>>tmp.3)
del z.txt
rename tmp.3 z.txt

message edited by nbrane


Report •
Related Solutions


Ask Question