Computing.Net > Forums > Disk Operating System > Find and Replace in Batch files

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 in Batch files

Reply to Message Icon

Name: ashlesha
Date: May 14, 2005 at 02:19:16 Pacific
OS: WIndows XP /DOS
CPU/Ram: Pentium 4- 504MB RAM
Comment:

Hi,
I want to create a file to do the following:
1. Create multiple copies of a folder and rename them in a numerically ascending order.
2. Open a specific file from the folder and change some of the contents.
3. save the changed file.
4. repeat actions 2 and 3 for all the copies. However, the changes in their individual files will be different for each folder.

I think i can do the first step. However, i cant find a command to find and Replace the text in a file.
I can use the findstr "string" path:filename cmd to find the required string, but how do i replace it?




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: May 14, 2005 at 04:04:10 Pacific
Reply:

No obvious way with the "tools" provided by DOS / XP.

I think you're stuck with 3rd party utils.

M2


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


0

Response Number 2
Name: wizard-fred
Date: May 15, 2005 at 16:40:25 Pacific
Reply:

1 - You cannot create multiple copies of a folder unless there in different folders. Your best method is to create the folders in one folder then copy the files. i.e.
md dir01
md diro2
md dir03
...
md dirnn
copy dirxx\*.* dir01
copy dirxx\*.* dir02
copy dirxx\*.* dir03
...
copy dirxx\*.* dirnn

2,3,4 To open, replace, save will require 3rd party software unless the contents is simple enough that it could be created by other means.


0

Response Number 3
Name: ashlesha
Date: May 16, 2005 at 00:49:21 Pacific
Reply:

Hi,

Thanks for your responses guys.

I can find text and write the changes back to the original file using the FOR command.
but is there a way to delete a particular line in the file?
m looking into 3rd party tools.


0

Response Number 4
Name: Mechanix2Go
Date: May 16, 2005 at 01:39:27 Pacific
Reply:

As to removing lines, assuming it's a text file, you can:

find /v "string" < file > newfile

which will put all the lines NOT containing the string into newdile.

***
The two 3rd party changers I use are:

Change9.11

Change.com

The change.com will work on files up to about 32KB. For bigger ones you need the EXE.

The EXE version has complete docs. I you decide to use the COM ver, ask for syntax help.

M2


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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Find and Replace in Batch files

How to find and replace a string www.computing.net/answers/dos/how-to-find-and-replace-a-string/7591.html

What does the % mean in batch files? www.computing.net/answers/dos/what-does-the-mean-in-batch-files/5925.html

Variables in batch files www.computing.net/answers/dos/variables-in-batch-files/12289.html