General discussion

Locked

Script to edit file contents

By nmccormick ·
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.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by mcmurray.mike In reply to Script to edit file conte ...

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.

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums