Discussion Locked

Script to edit file contents

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need to edit the contents of every file in a directory. I would like to automate this in a batch script, if possible. I am trying to use a FOR /D loop that executes a FOR /F loop that executes a series of commands that 1) makes a copy of the file, 2) sets a variable to the contents of the file, 3) executes a variable substitution command %var1:str1=str2% and 3) writes the variable back out to the file. I have started out with trying to make the basics of the variable substitution work with the following script but I can't seem to get it working in the batch script.

@ECHO OFF
set filetext=
FOR /f "delims=!" %%Z in (d:\stsrv_datawarehouse\exec_js_ld_combined_labor_facts.cmd.orig) do (
echo VARZ = %%Z
echo VARZ_EDITED = %%Z:edwprd=edwtst%%)

The results of the echo VARZ_EDITED line gives me the value of %%Z with :edwprd=edwtst appended to the end. What am I doing wrong? Does anyone have suggestions on how I can accomplish my goal?

Thanks in advance for your suggestions.

1 reply

by mcmurray.mike

The utility 'Advanced Find and Replace' can search through directories and replace any text with something else. It can also be run from a cmd prompt.
It's not free but does run unhindered for the first 17 days.
We use to it to scan through many GB and it completes in a minute or so.
If that doesn't meet the req, Kixtart scripts are a little more powerful and may get you results quicker.

This discussion is closed to new replies.