Friday, 15 February 2013

Editing a .txt file with a batch file -



Editing a .txt file with a batch file -

alright, i've looked around , tried adapt of code did find create work attempts i've tried have failed.

basically have text file, we'll phone call test.txt

text.txt contains these 3 lines:

var1=test1 var2=test2 var3=test3

basically trying batch file inquire me want alter value of var3 , alter value of var3 reflect typed in.

is possible? if how accomplish this?

class="lang-dos prettyprint-override">@echo off setlocal %%a in (var2change var2change2) set "%%a=" set /p var2change="change variable ? " set /p var2change2="change %var2change% ? " echo values before type q24373191.txt echo ============= :: create tempfile :maketemp set "tempfile=%temp%\%random%" if exist "%tempfile%*" (goto maketemp) else (echo.>"%tempfile%a") ( /f "tokens=1*delims==" %%a in ('type q24373191.txt') ( if /i "%%a"=="%var2change%" (echo %%a=%var2change2% ) else (echo %%a=%%b ) ) )>"%tempfile%a" re-create /y /b "%tempfile%a" q24373191.txt >nul del "%tempfile%a" echo values after type q24373191.txt goto :eof

i used file named q24373191.txt containing info testing.

batch-file

No comments:

Post a Comment