|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Echo to column positionI'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? <jnton***@gmail.com> wrote in message
news:6aca5e7e-9cbc-4cb1-b661-326b4243943a@w24g2000prd.googlegroups.com... Try this:> 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? @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.
Show quote
Hide quote
"Pegasus (MVP)" <I.***@fly.com.oz> wrote in message Interesting approach, I had not thought of doing it that way.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. 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
Show quote
Hide quote
"Al Dunbar" <aland***@hotmail.com> wrote in message Yes, the parentheses are nicer than the $ marker, especially from a script 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 maintenance point of view.
Show quote
Hide quote
On Feb 6, 6:08 pm, "Pegasus \(MVP\)" <I.***@fly.com.oz> wrote: Maybe a little variation on the theme (using two of foxidrives> "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. 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 ========= 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: Thanks, these tips are great!> > > > > > > "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 -
Batch Script to parse lines in text file
Command line parameters? Get attributes of user list from AD run once script Monitor redundent processes running on the Windows Server WMI Script, access denied? Deleting and re-installing printer with new name using login scrip send mail if ping faile Script for deleting folders + content in root of D:\ after # days Batch file to delete files dynamically |
|||||||||||||||||||||||