Fixed positions of variables in output file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jojolino
Posts: 3
Joined: 07 Sep 2009 08:05

Fixed positions of variables in output file

#1 Post by jojolino » 07 Sep 2009 08:20

Hi there!
I have found this forum with Google because I have a problem and no solution yet... Maybe someone here can help.

I have a batch file which gets the variables from another programm. This programm calls the batch with this command:

c:\test\mybatch.cmd %1 %2 and so on

My batch is simple, it includes only this line:

ECHO %~1 %~2%~3%~4%~5%~6 >> c:\tarisbatch\test_mi.txt

The data for my variables are:

%1 = 6006
%2 = 01.09.09
%3 = 07.09.09 and so on

The created text file contains this informations but my problem is I need the text on a specified position.
So the text from %2 should start at position 11 not directly after %1.
I cannot add manually spaces after %1 because %1 can have different length.
Is there a possibility to do this.

Example what I have

600601.09.0907.09.09
or with 0123456789 as variable %1
012345678901.09.0907.09.09

But if the variable %1 is shorter than 10 digits the missing digits should be filled in with blanks like this:

6006 01.09.0907.09.09

Cheers
Jürgen

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 08 Sep 2009 12:13

Pad %1 with 10 spaces, and then use the substring manipulation to present only the first 10 characters of the variable like this:

*UNTESTED*

Code: Select all

@echo off
set "tmpvar=%~1           "
echo.%tmpvar:~0,10%%~2%~3%~4%~5%~6>>c:\tarisbatch\test.mi.txt

Post Reply