General discussion
April 22, 2005 at 06:18 AM
nmccormick

Script to edit file contents

by nmccormick . Updated 21 years, 6 months ago

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 discussion is locked

All Comments