Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Echo to column position

Reply
Thread Tools Display Modes

Re: Echo to column position

 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      02-06-2009

<> wrote in message
news:6aca5e7e-9cbc-4cb1-b661-...
> 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.


 
Reply With Quote
 
 
 
 
Al Dunbar
Guest
Posts: n/a

 
      02-06-2009

"Pegasus (MVP)" <> wrote in message
news:...
>
> <> wrote in message
> news:6aca5e7e-9cbc-4cb1-b661-...
>> 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


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      02-06-2009

"Al Dunbar" <> wrote in message
news:...
>
> "Pegasus (MVP)" <> wrote in message
> news:...
>>
>> <> wrote in message
>> news:6aca5e7e-9cbc-4cb1-b661-...
>>> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible in "computer" to view files from top to bottom in 1st column then same again in next column to the right etc? J Windows Vista File Management 3 07-19-2008 01:23 AM
echo Steveair Windows Media Player 0 05-22-2005 02:32 PM
Echo... Echo Jet Windows MSN Messenger 3 01-03-2005 08:47 PM
echo Johnathon Clarke Windows Media Player 1 11-13-2004 05:59 AM
Echo Greg Windows Media Player 0 04-03-2004 10:59 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59