Computing.Net > Forums > Programming > Find and Replace

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Find and Replace

Reply to Message Icon

Name: ryanpete
Date: February 27, 2007 at 08:40:38 Pacific
OS: Xp Sp2
CPU/Ram: 2.99/512
Product: Dell/Optiplex GX520
Comment:

I need help making a batch file that will find the string "SERVICEACCOUNT" in the file settings.xml and replace it with the varible %username%.

any help would be great



Sponsored Link
Ads by Google

Response Number 1
Name: cup
Date: February 27, 2007 at 14:30:48 Pacific
Reply:

Are you allowed to use external exes or does it have to be vanilla XP.


0

Response Number 2
Name: ryanpete
Date: February 28, 2007 at 06:21:27 Pacific
Reply:

I would preffer to use vanilla XP, but at the moment I have it working with change.exe


0

Response Number 3
Name: dtech10
Date: February 28, 2007 at 06:51:37 Pacific
Reply:

Hi ryanpete

@echo off
setlocal EnableDelayedExpansion

@echo off > ~txt.txt
for /f "tokens=*" %%a in (settings.xml) do (
set C=%%a
set B=!C:SERVICEACCOUNT=%username%!
echo [!B!] >> ~txt.txt

)
del settings.xml
ren ~txt.txt settings.xml


0

Response Number 4
Name: Shr0Om
Date: February 28, 2007 at 06:56:06 Pacific
Reply:

Try this.
If you want the local username to be used, remove "set /p username=Username?:"


::CODE
@echo off
SetLocal EnableDelayedExpansion
set /p username=Username?:
For /F "tokens=1-2* delims=" %%A in (inputfile.xml) Do (
Set TxtLine=%%A
Echo !TxtLine:SERVICEACCOUNT=%username%!>>tmp)
del inputfile.xml
ren tmp inputfile.xml
endlocal


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


launching simultaneously ... How to read MSR or PhysMe...



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: Find and Replace

Find and Replace text in Batch File www.computing.net/answers/programming/find-and-replace-text-in-batch-file/12413.html

Batch find and replace www.computing.net/answers/programming/batch-find-and-replace/15145.html

CMD script find and replace text www.computing.net/answers/programming/cmd-script-find-and-replace-text/15412.html