Computing.Net > Forums > Programming > Replace text in file

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.

Replace text in file

Reply to Message Icon

Name: tmccar
Date: July 9, 2009 at 09:22:04 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

I want to replace some text fields in a file. The file will be similar to :
This is %name1%
This is %name2%
This is %name3%

And I will be writing different files based on the 3 name parameters. I want to be able to pass these 3 names as parameters to the batch file, so that it writes the names to the file. In other words, if I enter "Changeit.bat dog cat horse", I want an output file that reads:
This is dog
This is cat
This is horse

(I have simplified the output file greatly, but if I can get this to work, I can apply it to the big file).

Thanks!
Tom



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 9, 2009 at 11:13:50 Pacific
Reply:

@echo off > newfile & setLocal enableDELAYedexpansion

:loop
>> newfile echo This %1
shift
if "%1" neq "" goto :loop


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

M2


0

Response Number 2
Name: tmccar
Date: July 9, 2009 at 12:59:55 Pacific
Reply:

That's fantastic! Thans for the quick reply.

Tom


0
Reply to Message Icon

Related Posts

See More


Set word from text file a... Copy and rename mmost rec...



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: Replace text in file

Replacing text in files BAT file www.computing.net/answers/programming/replacing-text-in-files-bat-file/16818.html

replace text in file B from a variable in fil www.computing.net/answers/programming/replace-text-in-file-b-from-a-variable-in-fil/20338.html

Batch file to replace text in file www.computing.net/answers/programming/batch-file-to-replace-text-in-file/20070.html