Batch file to replace the string

July 23, 2009 at 23:57:05
Specs: Windows server 2003
i have a text file like this

## PROPERTY TO DECIDE IF THE DEFAULT IS SERVER ##
PROVIDER_URL_REQUIRED = N
TFA_EXTERNAL_LOCATION = D:\\auth.xml


i want to change the value of PROVIDER_URL_REQUIRED to Y.
Remember there is spaces between PROVIDER_URL_REQUIRED and '=' sign.
How to solve this using a batch file.


See More: Batch file to replace the string

Report •


#1
July 24, 2009 at 00:35:48
@echo off > newfile & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in (myfile) do (
if "%%a"=="PROVIDER_URL_REQUIRED = N" (
>> newfile echo.PROVIDER_URL_REQUIRED = Y
) else (
>> newfile echo.%%a
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 24, 2009 at 03:13:59
you can try this vbscript

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
	strLine = objFile.ReadLine
	If InStr(strLine,"PROVIDER_URL_REQUIRED")>0 Then
		strLine = Replace(strLine,"N","Y")
	End If
	WScript.Echo strLine
Loop
objFile.Close

save as myscript.vbs and on command line

c:\test> cscript /nologo myscript.vbs > newfile

GNU win32 packages | Gawk


Report •

Related Solutions


Ask Question