Home All Groups Group Topic Archive Search About
Author
6 Feb 2009 4:18 PM
jntoner1
I'm using windows batch scripts. Is there a way to echo variables to
specific column positions consistently? I've got VAR1 & VAR2 that can
vary from 5 to 40 characters in length that I'm echoing on the same
line. So I'm trying:

echo %VAR1%                                        %VAR2%

....and I'd like the results in the column for VAR2 to line up. I can
echo using tabs or spaces, but this shifts the VAR2 position a bit
depending on the value in VAR1. Is there any way to force my %VAR2% to
echo at a specific column position?

Author
6 Feb 2009 4:37 PM
Pegasus (MVP)
<jnton***@gmail.com> wrote in message
news:6aca5e7e-9cbc-4cb1-b661-326b4243943a@w24g2000prd.googlegroups.com...
> I'm using windows batch scripts. Is there a way to echo variables to
> specific column positions consistently? I've got VAR1 & VAR2 that can
> vary from 5 to 40 characters in length that I'm echoing on the same
> line. So I'm trying:
>
> echo %VAR1%                                        %VAR2%
>
> ...and I'd like the results in the column for VAR2 to line up. I can
> echo using tabs or spaces, but this shifts the VAR2 position a bit
> depending on the value in VAR1. Is there any way to force my %VAR2% to
> echo at a specific column position?

Try this:
@echo off
set var=%VAR1%                                         $
echo %var:~0,50%%VAR2%

Remove the "$" character - I only put it there to mark the end of the many
spaces I added to this line.
Are all your drivers up to date? click for free checkup

Author
6 Feb 2009 10:33 PM
Al Dunbar
Show quote Hide quote
"Pegasus (MVP)" <I.***@fly.com.oz> wrote in message
news:uaFblkHiJHA.2204@TK2MSFTNGP02.phx.gbl...
>
> <jnton***@gmail.com> wrote in message
> news:6aca5e7e-9cbc-4cb1-b661-326b4243943a@w24g2000prd.googlegroups.com...
>> I'm using windows batch scripts. Is there a way to echo variables to
>> specific column positions consistently? I've got VAR1 & VAR2 that can
>> vary from 5 to 40 characters in length that I'm echoing on the same
>> line. So I'm trying:
>>
>> echo %VAR1%                                        %VAR2%
>>
>> ...and I'd like the results in the column for VAR2 to line up. I can
>> echo using tabs or spaces, but this shifts the VAR2 position a bit
>> depending on the value in VAR1. Is there any way to force my %VAR2% to
>> echo at a specific column position?
>
> Try this:
> @echo off
> set var=%VAR1%                                         $
> echo %var:~0,50%%VAR2%
>
> Remove the "$" character - I only put it there to mark the end of the many
> spaces I added to this line.

Interesting approach, I had not thought of doing it that way.

But to avoid having to use a marker like "$" and take it out because you do
not want it in the output, I'd suggest using parentheses:

    @echo off
    (set var=%VAR1%                                         )
    echo %var:~0,50%%VAR2%

/Al
Author
6 Feb 2009 11:08 PM
Pegasus (MVP)
Show quote Hide quote
"Al Dunbar" <aland***@hotmail.com> wrote in message
news:OLSy1rKiJHA.996@TK2MSFTNGP02.phx.gbl...
>
> "Pegasus (MVP)" <I.***@fly.com.oz> wrote in message
> news:uaFblkHiJHA.2204@TK2MSFTNGP02.phx.gbl...
>>
>> <jnton***@gmail.com> wrote in message
>> news:6aca5e7e-9cbc-4cb1-b661-326b4243943a@w24g2000prd.googlegroups.com...
>>> I'm using windows batch scripts. Is there a way to echo variables to
>>> specific column positions consistently? I've got VAR1 & VAR2 that can
>>> vary from 5 to 40 characters in length that I'm echoing on the same
>>> line. So I'm trying:
>>>
>>> echo %VAR1%                                        %VAR2%
>>>
>>> ...and I'd like the results in the column for VAR2 to line up. I can
>>> echo using tabs or spaces, but this shifts the VAR2 position a bit
>>> depending on the value in VAR1. Is there any way to force my %VAR2% to
>>> echo at a specific column position?
>>
>> Try this:
>> @echo off
>> set var=%VAR1%                                         $
>> echo %var:~0,50%%VAR2%
>>
>> Remove the "$" character - I only put it there to mark the end of the
>> many spaces I added to this line.
>
> Interesting approach, I had not thought of doing it that way.
>
> But to avoid having to use a marker like "$" and take it out because you
> do not want it in the output, I'd suggest using parentheses:
>
>    @echo off
>    (set var=%VAR1%                                         )
>    echo %var:~0,50%%VAR2%
>
> /Al

Yes, the parentheses are nicer than the $ marker, especially from a script
maintenance point of view.
Author
7 Feb 2009 5:08 PM
Tom Lavedas
Show quote Hide quote
On Feb 6, 6:08 pm, "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote:
> "Al Dunbar" <aland***@hotmail.com> wrote in message
>
> news:OLSy1rKiJHA.996@TK2MSFTNGP02.phx.gbl...
>
>
>
>
>
> > "Pegasus (MVP)" <I.***@fly.com.oz> wrote in message
> >news:uaFblkHiJHA.2204@TK2MSFTNGP02.phx.gbl...
>
> >> <jnton***@gmail.com> wrote in message
> >>news:6aca5e7e-9cbc-4cb1-b661-326b4243943a@w24g2000prd.googlegroups.com....
> >>> I'm using windows batch scripts. Is there a way to echo variables to
> >>> specific column positions consistently? I've got VAR1 & VAR2 that can
> >>> vary from 5 to 40 characters in length that I'm echoing on the same
> >>> line. So I'm trying:
>
> >>> echo %VAR1%                                        %VAR2%
>
> >>> ...and I'd like the results in the column for VAR2 to line up. I can
> >>> echo using tabs or spaces, but this shifts the VAR2 position a bit
> >>> depending on the value in VAR1. Is there any way to force my %VAR2% to
> >>> echo at a specific column position?
>
> >> Try this:
> >> @echo off
> >> set var=%VAR1%                                         $
> >> echo %var:~0,50%%VAR2%
>
> >> Remove the "$" character - I only put it there to mark the end of the
> >> many spaces I added to this line.
>
> > Interesting approach, I had not thought of doing it that way.
>
> > But to avoid having to use a marker like "$" and take it out because you
> > do not want it in the output, I'd suggest using parentheses:
>
> >    @echo off
> >    (set var=%VAR1%                                         )
> >    echo %var:~0,50%%VAR2%
>
> > /Al
>
> Yes, the parentheses are nicer than the $ marker, especially from a script
> maintenance point of view.

Maybe a little variation on the theme (using two of foxidrives
tricks) ...

@echo off
  set "var1=VAR1"
  set "var2=VAR2"
  set count=50
  for /l %%a in (1,1,%count%) do call set "var1=%%var1%% "
  call echo %%var1:~0,%count%%%%var2%

It has the advantage of allowing the padding width to be varied by
changing the value of the variable, COUNT.

Tom Lavedas
=========
Author
13 Feb 2009 4:39 PM
jntoner1
On Feb 7, 12:08 pm, Tom Lavedas <tglba***@cox.net> wrote:
Show quoteHide quote
> On Feb 6, 6:08 pm, "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote:
>
>
>
>
>
> > "Al Dunbar" <aland***@hotmail.com> wrote in message
>
> >news:OLSy1rKiJHA.996@TK2MSFTNGP02.phx.gbl...
>
> > > "Pegasus (MVP)" <I.***@fly.com.oz> wrote in message
> > >news:uaFblkHiJHA.2204@TK2MSFTNGP02.phx.gbl...
>
> > >> <jnton***@gmail.com> wrote in message
> > >>news:6aca5e7e-9cbc-4cb1-b661-326b4243943a@w24g2000prd.googlegroups.com...
> > >>> I'm using windows batch scripts. Is there a way to echo variables to
> > >>> specific column positions consistently? I've got VAR1 & VAR2 that can
> > >>> vary from 5 to 40 characters in length that I'm echoing on the same
> > >>> line. So I'm trying:
>
> > >>> echo %VAR1%                                        %VAR2%
>
> > >>> ...and I'd like the results in the column for VAR2 to line up. I can
> > >>> echo using tabs or spaces, but this shifts the VAR2 position a bit
> > >>> depending on the value in VAR1. Is there any way to force my %VAR2% to
> > >>> echo at a specific column position?
>
> > >> Try this:
> > >> @echo off
> > >> set var=%VAR1%                                         $
> > >> echo %var:~0,50%%VAR2%
>
> > >> Remove the "$" character - I only put it there to mark the end of the
> > >> many spaces I added to this line.
>
> > > Interesting approach, I had not thought of doing it that way.
>
> > > But to avoid having to use a marker like "$" and take it out because you
> > > do not want it in the output, I'd suggest using parentheses:
>
> > >    @echo off
> > >    (set var=%VAR1%                                         )
> > >    echo %var:~0,50%%VAR2%
>
> > > /Al
>
> > Yes, the parentheses are nicer than the $ marker, especially from a script
> > maintenance point of view.
>
> Maybe a little variation on the theme (using two of foxidrives
> tricks) ...
>
>  @echo off
>   set "var1=VAR1"
>   set "var2=VAR2"
>   set count=50
>   for /l %%a in (1,1,%count%) do call set "var1=%%var1%% "
>   call echo %%var1:~0,%count%%%%var2%
>
> It has the advantage of allowing the padding width to be varied by
> changing the value of the variable, COUNT.
>
> Tom Lavedas
> =========- Hide quoted text -
>
> - Show quoted text -

Thanks, these tips are great!

Bookmark and Share

Post Thread options