AWK: Display variable width columns fields into fixed spaced Column fields Format in Unix. $ cat temp.txtQUEUE(XYZ1.REQ.YAM.ALIAS) TYPE(QCLUSTER) CLUSTER(MYCLUS) CLUSQMGR(BLAHBLAH) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(XYZ4.REPL.YAM) TYPE(QCLUSTER) CLUSTER(MYSTER) CLUSQMGR(BLAHBLAHBLAHBLAH) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(XYZ8.REQ.YAM) TYPE(QCLUSTER) CLUSTER(MYCTER) CLUSQMGR(BLAHBLAH) CLUSQT(QALIAS) DEFPSIST(NO) PUT(DISABLED)QUEUE(XYZ8.REPLY.YAM) TYPE(QCLUSTER) CLUSTER( ) CLUSQMGR(ABCD) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(KK.RAMAN.K.LQ) TYPE(QCLUSTER) CLUSTER(MYCLUSTER) CLUSQMGR() CLUSQT(QLOCAL) DEFPSIST(NO) PUT(ENABLED)QUEUE(KK.RAMAN.KATHPALIA) TYPE(QREMOTE) CLUSTER(MYCLUSTER) CLUSQMGR(ABCD) CLUSQT(QLOCAL) DEFPSIST(NO) PUT(ENABLED)QUEUE(KATHPLAIA.RAMAN) TYPE( ) CLUSTER( ) CLUSQMGR(ABCD) CLUSQT(QLOCAL) DEFPSIST(NO) PUT(ENABLED)QUEUE(XYZ8.REQ.EQUAL.LQ) TYPE(QCLUSTER) CLUSTER(MYCLUSTER) CLUSQMGR(BLAHBLAHBLAHBLAH) CLUSQT(QLOCAL) DEFPSIST(YES) PUT(ENABLED)QUEUE(XYZ9.RAMAN.EQUAL.LQ) TYPE(QL) CLUSTER(MYCLUSTER) CLUSQMGR(ABCD) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(XX10.REPL.EQUAL.ALIAS) TYPE(QA) CLUSTER(YOURC) CLUSQMGR(ABCD) CLUSQT(QALIAS) DEFPSIST(YES) PUT(DISABLED)QUEUE(XX10.KATHPLAIA.EQUAL.LOCAL) TYPE(LOCALQ) CLUSTER(MYCLUSTER) CLUSQMGR(BLAHBLAHBLAHBLAH) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(XX11.RAMAN.EQUAL.LOCAL) TYPE(QCLUSTER) CLUSTER(MYCLUS) CLUSQMGR(BLAHBLAH) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(XX11.REQ.LOCAL) TYPE(QCLUSTER) CLUSTER(MYCLUSTER) CLUSQMGR(ABCD) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(RAMAN_KATHPLIA_000_11.REQ.EQUAL.REMOTE.QUEUE) TYPE(QCLUSTER) CLUSTER(MYCLUS) CLUSQMGR(BLAHBLAHBLAHBLAH) CLUSQT(QALIAS) DEFPSIST(YES) PUT(DISABLED)QUEUE(XYZ2.REQ.RAMAN.REMOTE.QUEUE) TYPE(QLOCAL) CLUSTER(STER) CLUSQMGR(BLAHBLAH) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)QUEUE(XYZ2.REQ.EQUAL.REMOTE.QUEUE) TYPE(QCLUSTER) CLUSTER( ) CLUSQMGR(BLAHBLAHBLAHBLAH) CLUSQT(QALIAS) DEFPSIST(YES) PUT(ENABLED)Expected: A neat column displayThis can be achieved by column command:$ cat temp.txt | column -tQUEUE(XYZ1.REQ.YAM.ALIAS)                            TYPE(QCLUSTER)  CLUSTER(MYCLUS)     CLUSQMGR(BLAHBLAH)          CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ4.REPL.YAM)                                 TYPE(QCLUSTER)  CLUSTER(MYSTER)     CLUSQMGR(BLAHBLAHBLAHBLAH)  CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ8.REQ.YAM)                                  TYPE(QCLUSTER)  CLUSTER(MYCTER)     CLUSQMGR(BLAHBLAH)          CLUSQT(QALIAS)              DEFPSIST(NO)    PUT(DISABLED)QUEUE(XYZ8.REPLY.YAM)                                TYPE(QCLUSTER)  CLUSTER(            )                           CLUSQMGR(ABCD)              CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(KK.RAMAN.K.LQ)                                 TYPE(QCLUSTER)  CLUSTER(MYCLUSTER)  CLUSQMGR()                  CLUSQT(QLOCAL)              DEFPSIST(NO)    PUT(ENABLED)QUEUE(KK.RAMAN.KATHPALIA)                            TYPE(QREMOTE)   CLUSTER(MYCLUSTER)  CLUSQMGR(ABCD)              CLUSQT(QLOCAL)              DEFPSIST(NO)    PUT(ENABLED)QUEUE(KATHPLAIA.RAMAN)                               TYPE(           )                   CLUSTER(                    )                           CLUSQMGR(ABCD)  CLUSQT(QLOCAL)  DEFPSIST(NO)  PUT(ENABLED)QUEUE(XYZ8.REQ.EQUAL.LQ)                             TYPE(QCLUSTER)  CLUSTER(MYCLUSTER)  CLUSQMGR(BLAHBLAHBLAHBLAH)  CLUSQT(QLOCAL)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ9.RAMAN.EQUAL.LQ)                           TYPE(QL)        CLUSTER(MYCLUSTER)  CLUSQMGR(ABCD)              CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(XX10.REPL.EQUAL.ALIAS)                         TYPE(QA)        CLUSTER(YOURC)      CLUSQMGR(ABCD)              CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(DISABLED)QUEUE(XX10.KATHPLAIA.EQUAL.LOCAL)                    TYPE(LOCALQ)    CLUSTER(MYCLUSTER)  CLUSQMGR(BLAHBLAHBLAHBLAH)  CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(XX11.RAMAN.EQUAL.LOCAL)                        TYPE(QCLUSTER)  CLUSTER(MYCLUS)     CLUSQMGR(BLAHBLAH)          CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(XX11.REQ.LOCAL)                                TYPE(QCLUSTER)  CLUSTER(MYCLUSTER)  CLUSQMGR(ABCD)              CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(RAMAN_KATHPLIA_000_11.REQ.EQUAL.REMOTE.QUEUE)  TYPE(QCLUSTER)  CLUSTER(MYCLUS)     CLUSQMGR(BLAHBLAHBLAHBLAH)  CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(DISABLED)QUEUE(XYZ2.REQ.RAMAN.REMOTE.QUEUE)                   TYPE(QLOCAL)    CLUSTER(STER)       CLUSQMGR(BLAHBLAH)          CLUSQT(QALIAS)              DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ2.REQ.EQUAL.REMOTE.QUEUE)                   TYPE(QCLUSTER)  CLUSTER(            )                           CLUSQMGR(BLAHBLAHBLAHBLAH)  CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)Problems: Certain AIX and Solaris hosts doesn't have column command. So can't use column universally.Even with usage of column:(a) ( ) expands to (            ) (b) More space than necessary is inserted between fields making few rows to fold into next line thus messing up formatting (19 Inch display monitor).Questions: Using awk, Problem 2 re-surfaces (or worse for few lines). Please see below. Can someone suggest a better awk statement ?Also interested to see if Problem 2 can be resolved using column command ? $ cat temp.txt | awk '{printf %-55s  %-15s %-20s %-35s %-15s %-15s %-15s \n, $1,$2,$3,$4,$5,$6,$7}'QUEUE(XYZ1.REQ.YAM.ALIAS)                                TYPE(QCLUSTER)  CLUSTER(MYCLUS)      CLUSQMGR(BLAHBLAH)                  CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ4.REPL.YAM)                                     TYPE(QCLUSTER)  CLUSTER(MYSTER)      CLUSQMGR(BLAHBLAHBLAHBLAH)          CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ8.REQ.YAM)                                      TYPE(QCLUSTER)  CLUSTER(MYCTER)      CLUSQMGR(BLAHBLAH)                  CLUSQT(QALIAS)  DEFPSIST(NO)    PUT(DISABLED)QUEUE(XYZ8.REPLY.YAM)                                    TYPE(QCLUSTER)  CLUSTER(             )                                   CLUSQMGR(ABCD)  CLUSQT(QALIAS)  DEFPSIST(YES)QUEUE(KK.RAMAN.K.LQ)                                     TYPE(QCLUSTER)  CLUSTER(MYCLUSTER)   CLUSQMGR()                          CLUSQT(QLOCAL)  DEFPSIST(NO)    PUT(ENABLED)QUEUE(KK.RAMAN.KATHPALIA)                                TYPE(QREMOTE)   CLUSTER(MYCLUSTER)   CLUSQMGR(ABCD)                      CLUSQT(QLOCAL)  DEFPSIST(NO)    PUT(ENABLED)QUEUE(KATHPLAIA.RAMAN)                                   TYPE(           )                    CLUSTER(                            )               CLUSQMGR(ABCD)  CLUSQT(QLOCAL)QUEUE(XYZ8.REQ.EQUAL.LQ)                                 TYPE(QCLUSTER)  CLUSTER(MYCLUSTER)   CLUSQMGR(BLAHBLAHBLAHBLAH)          CLUSQT(QLOCAL)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ9.RAMAN.EQUAL.LQ)                               TYPE(QL)        CLUSTER(MYCLUSTER)   CLUSQMGR(ABCD)                      CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(XX10.REPL.EQUAL.ALIAS)                             TYPE(QA)        CLUSTER(YOURC)       CLUSQMGR(ABCD)                      CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(DISABLED)QUEUE(XX10.KATHPLAIA.EQUAL.LOCAL)                        TYPE(LOCALQ)    CLUSTER(MYCLUSTER)   CLUSQMGR(BLAHBLAHBLAHBLAH)          CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(XX11.RAMAN.EQUAL.LOCAL)                            TYPE(QCLUSTER)  CLUSTER(MYCLUS)      CLUSQMGR(BLAHBLAH)                  CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(XX11.REQ.LOCAL)                                    TYPE(QCLUSTER)  CLUSTER(MYCLUSTER)   CLUSQMGR(ABCD)                      CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(RAMAN_KATHPLIA_000_11.REQ.EQUAL.REMOTE.QUEUE)      TYPE(QCLUSTER)  CLUSTER(MYCLUS)      CLUSQMGR(BLAHBLAHBLAHBLAH)          CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(DISABLED)QUEUE(XYZ2.REQ.RAMAN.REMOTE.QUEUE)                       TYPE(QLOCAL)    CLUSTER(STER)        CLUSQMGR(BLAHBLAH)                  CLUSQT(QALIAS)  DEFPSIST(YES)   PUT(ENABLED)QUEUE(XYZ2.REQ.EQUAL.REMOTE.QUEUE)                       TYPE(QCLUSTER)  CLUSTER(             )                                   CLUSQMGR(BLAHBLAHBLAHBLAH) CLUSQT(QALIAS)  DEFPSIST(YES)Field info:All fields are bound and don't expand beyond certain length.        - Max Width field 1 = 55        - Max Width field 2 = 15        - Max Width field 3 = 20        - Max Width field 4 = 30        - Max Width field 5 = 15        - Max Width field 6 = 15        - Max Width field 7 = 15Limitation: I want to optimize the display for least sized monitor in organisation == 19 InchesSo, I want to minimize the gap between columns to a single space. Possibly, checkered columns (like MS Excel)
awk - , fixed width columns
text processing;awk;text formatting
I would just replace the troublesome ( ) before processing:sed 's/( )/()/g' temp.txt | awk '{printf %-55s  %-15s %-20s %-35s %-15s %-15s %-15s \n, $1,$2,$3,$4,$5,$6,$7}'If the number of spaces varies, usesed 's/( \+)/()/g'instead.