[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Removing Spaces in a Batch File

Posted on 2005-05-11
4
Medium Priority
?
189 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:ben1211
  • 3
4 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 13979181
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 <>|^%?
0
 

Author Comment

by:ben1211
ID: 13986985
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
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 13990575
Sorry, my error; two additional spaces after the first two lines, because they didn't have any spaces in them.
This takes care of that (needs W2k or later) and changes the execution month as well:

@echo off
setlocal enabledelayedexpansion
set InputFile=c:\batch_bo_report_param.txt
set OutputFile=c:\batch_bo_report_param-new.txt
set NewExecutionDate=2005-05-10
for /f "tokens=1,2 delims=-" %%a in ("%NewExecutionDate%") do set NewExecutionMonth=%%a-%%b
if exist "%OutputFile%" del "%OutputFile%"
for /f "tokens=1,2 delims==" %%a in ('type "%InputFile%"') do (
  set aaToken=%%a
  if /i "!aaToken:~0,14!"=="Execution Date" (
    >>"%OutputFile%" echo Execution Date ^(YYYY-MM-DD^) : =%NewExecutionDate%
  ) else (
    if /i "%aaToken:~0,15%"=="Execution Month" (
      >>"%OutputFile%" echo Execution Month ^(YYYY-MM-DD^) : =%NewExecutionMonth%
    ) else (
      >>"%OutputFile%" echo %%a=%%b
    )
  )
)
0
 
LVL 85

Expert Comment

by:oBdA
ID: 13990928
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" (
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question