Page 1 of 1

output data alignment.

Posted: 04 Jan 2014 03:00
by Mahendra
I have below script and i am able to get the required info. but the string sizes are different in the output. so that i want to print the output in a grid format like as follows. could some one please advice me to print the output in grid format.

ASDF | 67 | ujuhh
QWEDD | 54 | jhj




@echo off
setlocal EnableDelayedExpansion
echo ---------------------------------------------------------------------------
echo Queue ^| type ^|put ^| get ^|Maxdepth^|cudepth^|usage
echo ----------------------------------------------------------------------------
set details=
echo "display ql(*)" | runmqsc QMGR > output.txt
for /F "delims=" %%a in (output.txt) do (
set details=!details!%%a
set property=%%a
if "!property:usage=!" neq "!property!" (
for /F "tokens=1-14 delims=()" %%a in ("!details!") do (
echo %%b^|%%d^|%%f^|%%h^|%%j^|%%l^|%%n
)
set details=
)
)


it should be like a perfect table of contents.
Queue length max 48 chars like type 6 , put 8 maxdepth 7 curdepth 7 usage 7 chars

---------------------------------------------------
Queue -------------------------|type--|put----| get--- |Maxdepth|cudepth|usage
----------------------------------------------------------------------------
system.jdfkjdhfkdj.khkdhfkd------|LOCAL|enabled|enabled|10000----|100----|NORMAL
kjhfksjdfhdkfjhkdsfjds_2323.sdjj---|LOCAL|enabled|disabled|10000----|100----|NORMAL

Re: output data alignment.

Posted: 04 Jan 2014 03:09
by foxidrive
Remember this thread? viewtopic.php?f=3&t=4037

Did you get a solution there?

Re: output data alignment.

Posted: 04 Jan 2014 03:35
by Mahendra
thanks...i got the solution for that topic...

Re: output data alignment.

Posted: 04 Jan 2014 03:36
by Mahendra
i am looking to print out in perfect grid format of output for variable length of strings.

Re: output data alignment.

Posted: 04 Jan 2014 09:14
by penpen
Just use the batch variable string replacement (for example "!line:~-4!" as foxidrive has linked), but now 7 times (Queue, type, ...):

Code: Select all

:: only the for loop changed, so other code stays
:: (...)
for /F "tokens=1-14 delims=()" %%a in ("!details!") do (
:: leading spaces (as many, as you need per column, so 48 spaces for cQueue, ...)
set "cQueue=                                                %%b"
set "cType=      %%d"
set "cPut=        %%f"
set "cGet=       %%h"
set "cMaxdepth=       %%j"
set "cCudepth=       %%l"
set "cUsage=       %%n"
echo !cQueue:~-48!^|!cType:~-6!^|!cPut:~-8!^|!cGet:~7!^|!cMaxdepth:~-7!^|!cCudepth:~-7!^|!cUsage:~-7!
:: (...)

penpen

Re: output data alignment.

Posted: 05 Jan 2014 08:30
by Mahendra
excellent,...:0
Many thanks for the solution.

Re: output data alignment.

Posted: 05 Jan 2014 08:55
by Squashman
dont we have a Format function in the library that would work for this?