Link to home
Start Free TrialLog in
Avatar of ben1211
ben1211Flag for Malaysia

asked on

Removing Spaces in a Batch File

Previously I had asked a question on how I can replace the Execution date with a date entered by the user. Basically it is to write the Execution Date & Execution Month into the text file called batch_bo_report_param.txt.  The text file looks like this:

BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03
Batch Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\Report\
Log Batch Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\Log\
Batch Result Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\Result_Report\
Logo Path Name : =C:\MDB_BATCH_BO_REPORTS\Param\KLLogo.bmp


I was given the code by obda:

@echo off
setlocal
set InputFile=c:\batch_bo_report_param.txt
set OutputFile=c:\batch_bo_report_param-new.txt
set NewExecutionDate=2005-05-10
if exist "%OutputFile%" del "%OutputFile%"
for /f "tokens=1,2*" %%a in ('type "%InputFile%"') do (
 if /i "%%a %%b"=="Execution Date" (
   >>"%OutputFile%" echo Execution Date ^(YYYY-MM-DD^) : =%NewExecutionDate%
 ) else (
   >>"%OutputFile%" echo %%a %%b %%c
 )
)

Now the code works fine. It actualy creates a new batch_bo_report_param file and replaces the Execution Date. This batch_bo_report_param.txt file is actually used to pass certain data to some other file. Anyway, I normally run another batch report (CTPD950.bat) which in turn gets its Execution date from the batch_bo_report_param.txt file.

The problem is, the CTPD950.bat file will not run when this new param file is created. So I tested it out by cutting the exact lines (posted right above) and pasted it in the new batch_bo_report_param.txt file and the report CTPD950 ran. The four lines that I cut and pasted from the old batch_bo_report_param.txt file to the new one are:

BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03


Is there any possible way of doing like a vbCrLf for a DOS batch file? I suspect this may be the cause, but I am uncertain. There is something about these four line that is causing the CTPD950.bat report not to run when it reads the newly created batch_bo_report_param.txt

I really need help on this as I am totally out of ideas.

Thank You
Avatar of oBdA
oBdA

The script in its current version will only replace the "Execution Date" line; might it be necessary to change the "Execution Month" line as well?
Then can you post the lines that are *not* working (if necessary, replace spaces with underscores or tildes or whatever, so that they don't get lost)?
And another question: is especially the data in bopass indeed "bopass", or does this contain any special characters like <>|^%?
Avatar of ben1211

ASKER

obda,

Yes, it is necessary to change the Execution Month as well. So, it is the Execution Date & Execution Month that needs to be changed.

I believe the lines that are causing the problem are:

BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03

bopass does not contain any special characters. it is meant to be that way.

obda, in a Batch File, is there any command like VBS such as vbCrLf? I believe this puts the line on the left of the file. I am not sure if this removes any spaces from the left or not. Any idea?

Thank You.

Ben
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, typo in the "Execution Month" line.
Replace the percent signs in this line
if /i "%aaToken:~0,15%"=="Execution Month" (
with exclamation marks:
if /i "!aaToken:~0,15!"=="Execution Month" (