Computing.Net > Forums > Programming > Batch file to replace the string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch file to replace the string

Reply to Message Icon

Name: aswabh
Date: July 23, 2009 at 23:57:05 Pacific
OS: Windows server 2003
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 24, 2009 at 00:35:48 Pacific
Reply:

@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


0

Response Number 2
Name: ghostdog
Date: July 24, 2009 at 03:13:59 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Ti-83 full rpg games Can't rename files.



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to replace the string

Batch File To Find The String Count www.computing.net/answers/programming/batch-file-to-find-the-string-count/20226.html

Batch file to replace a word www.computing.net/answers/programming/batch-file-to-replace-a-word/15770.html

Batch file to append created date www.computing.net/answers/programming/batch-file-to-append-created-date/14993.html