output data alignment.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mahendra
Posts: 26
Joined: 23 Sep 2012 02:29

output data alignment.

#1 Post by Mahendra » 04 Jan 2014 03:00

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: output data alignment.

#2 Post by foxidrive » 04 Jan 2014 03:09

Remember this thread? viewtopic.php?f=3&t=4037

Did you get a solution there?

Mahendra
Posts: 26
Joined: 23 Sep 2012 02:29

Re: output data alignment.

#3 Post by Mahendra » 04 Jan 2014 03:35

thanks...i got the solution for that topic...

Mahendra
Posts: 26
Joined: 23 Sep 2012 02:29

Re: output data alignment.

#4 Post by Mahendra » 04 Jan 2014 03:36

i am looking to print out in perfect grid format of output for variable length of strings.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: output data alignment.

#5 Post by penpen » 04 Jan 2014 09:14

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

Mahendra
Posts: 26
Joined: 23 Sep 2012 02:29

Re: output data alignment.

#6 Post by Mahendra » 05 Jan 2014 08:30

excellent,...:0
Many thanks for the solution.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: output data alignment.

#7 Post by Squashman » 05 Jan 2014 08:55

dont we have a Format function in the library that would work for this?

Post Reply