How do I insert a string into a file

December 14, 2009 at 10:35:22
Specs: Windows Server 2003
The below batch file is designed to generate variables which are used to identify directory paths and execute scripts. I am a novice at batch programming and I need to insert the BOLD string at a specific line (Ex. Line 16) of the BOLD/Italic file so that the log file is created before scripts within the target file are run:



set /p env=Enter the environment to run STORE* scripts for:
set /p pw=Enter the PS password for the environment to run STORE* scripts for:
set /p logdir=Enter the update, patch, etc, that the scripts are being run for:

mkdir E:\PSFT\CA\%env%\out\%logdir%

echo SET LOG E:\PSFT\CA\%env%\out\%logdir%\STOREPT.LOG; >> E:\PSFT\HRTRN\src\cbl\base\STOREPT.DMS

Title Run STORE* Scripts for %env%


ECHO This script will run the required STORE* scripts for %env%.



ECHO If logs are needed for review, they can be found here:
ECHO E:\PSFT\CA\%env%\out\%logdir%



E:\PSFT\%env%\bin\client\winx86\psdmtx.exe -CT MICROSFT -CS PSFTAPP -CD %env% -CO PS -CP %pw% -SS NO -SN NO -FP


Can anyone help with this?


See More: How do I insert a string into a file

Report •

December 14, 2009 at 20:42:51
not tested, assumes var.s assigned vals in prior code:
set logfile=%log%
:: E:\PSFT\HRTRN\src\cbl\base\STOREPT.DMS ?
set /a ins=16
set /a cc=0
set newline=SET LOG E:\PSFT\CA\%env%\out\%logdir%\STOREPT.LOG
for /f "tokens=* delims=" %%a in (%logfile%) do (
set zz=%%a
call :xxx)
move /y newfile %logfile%
goto :EOF

set /a cc+=1
if %cc% equ %ins% echo %newline% >> newfile
echo %zz% >> newfile

Report •

December 15, 2009 at 17:54:02

This solution worked, however, in order to simplify things, can it be changed to simply insert the string at the beginning of the file? The only issue with the solution, as is, is that it loops thru numerous times regardless of what I set the target row value to. This would be more of a time issue because, ultimately, this script will run 5 or more scripts some of which run for 3-5 minutes each.

I greatly appreciate the assistance!

Report •

December 16, 2009 at 01:58:10
This might work, don't know if it will speed things up or not.
this just appends your %logfile% to the SET LOG line:

echo SET LOG E:\PSFT\CA\%env%\out\%logdir%\STOREPT.LOG > AA.tmp
copy AA.tmp + %logfil% script2
del AA.tmp
move /y script2 %logile%

if i knew more about what was going on, i could maybe be better, but i'm really not sure what exactly is going on. (f/e: no clue "target row" assignment...)
NOTE: %logfil% will need to be reset each session, or else it will aggragate cumulative additions to line one! (yunowhatimean: line 1+ line1+line1+logfile...)
hope i've helped...

Report •

Related Solutions

Ask Question