awk -, colunas de largura fixa

4

AWK: Exibe campos de colunas de largura variável em campos de Coluna espaçados fixos Formato no Unix.

$ cat temp.txt
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) 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)

Esperado: uma exibição de coluna nítida

Isso pode ser obtido pelo comando "column":

$ cat temp.txt | column -t
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)   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)

Problemas:

  1. Certos hosts do AIX e do Solaris não possuem o comando "column". Por isso, não posso usar "coluna" universalmente.

  2. Mesmo com o uso da coluna:

    (a) ( ) expande para ( )

    (b) Mais espaço do que o necessário é inserido entre os campos, fazendo algumas linhas para dobrar na próxima linha, atrapalhando a formatação (monitor de 19 polegadas).

Perguntas:

  1. Usando o awk, o Problema 2 reaparece (ou pior para algumas linhas). Por favor veja abaixo. Alguém pode sugerir uma declaração awk melhor?
  2. Também interessado em ver se o Problema 2 pode ser resolvido usando o comando "column"?

$ 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)

Informação de campo:

Todos os campos estão vinculados e não se expandem além do limite.

- 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 = 15

Limitação :

Eu quero otimizar a exibição do monitor de menor tamanho na organização == 19 Polegadas

Então, quero minimizar o intervalo entre as colunas para um único espaço. Possivelmente, colunas quadriculadas (como o MS Excel)

    
por Raman Kathpalia 17.03.2017 / 20:14

4 respostas

5

Gostaria apenas de substituir o problemático ( ) antes de processar:

sed 's/( )/()/g' temp.txt | awk '{printf "%-55s  %-15s %-20s %-35s %-15s %-15s %-15s \n", $1,$2,$3,$4,$5,$6,$7}'

Se o número de espaços varia, use

sed 's/( \+)/()/g'

em vez disso.

    
por 17.03.2017 / 20:19
4

Uma solução fácil seria usar o ) como o separador de campo para awk . Isso contorna os dois problemas que você mencionou. No entanto, isso também remove o ) de cada linha, portanto, é necessário adicioná-los novamente quando você chamar printf :

$ awk -F')' '{printf "%-55s  %-15s %-20s %-35s %-15s %-15s %-15s \n",
                      $1")",$2")",$3")",$4")",$5")",$6")",$7")"}' temp.txt 
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)   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)   

Eu não entendo porque você tem esses espaços extras. Por que não algo assim:

$ awk -F')' '{printf "%-51s%-15s%-20s%-28s%-15s%-15s%-15s\n",
                      $1")",$2")",$3")",$4")",$5")",$6")",$7")"}' temp.txt 
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)  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)  

Outra abordagem é converter todos os espaços seguindo um ) para guias e usar guias como o separador de campo:

$ sed 's/)  */)\t/g' temp.txt | 
    awk -F'\t' '{printf "%-52s%-15s%-20s%-28s%-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)  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)   
    
por 17.03.2017 / 23:18
3

Você pode substituir ( ) por algo como +++ , passá-lo para column -t e substituir +++ :

$ sed 's/( )\{1,\}/+++/g' temp.txt | column -t | sed 's/+++/\( \)/g' 
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)  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)

Isso não funciona para variáveis com espaço em branco se você quiser manter o espaçamento exato entre ( ) .

    
por 17.03.2017 / 21:08
3

Método 1: tbl

# Assumindo o GNU sed. Sed gera os comandos tbl em tempo real e, em seguida, tbl é executado para gerar a saída desejada.

sed -e '
   1i\
.TS\
tab( );

   1{
      h;s/(\s\+)/(,)/g;
      s/\s\+$//;s/^\s\+//;s/\s\+/ /g;
      s/\S\+//g
      s/$/ /;s/ /l&/g;s/.$/./
      G;b
   }
   s/(\s\+)/(,)/g
   $a\
.TE
' | tbl - | nroff -Tascii -ms | sed '/./!d; s/(,)/( )/g'

Explicação

Actually the sed portion is needlessly complex in our case. I wrote to make it
not being dependent upon how many columns are there in the data & looking at the
data in hand come up with the tbl syntax. Since in our case we are sure there are
exactly 7 columns so the sed code could have been simply be written simply':
(which is what the sed logic actually was generating essentially,
 those 7  space separated ells and a trailing dot)

sed -e '
   1i\
.TS\
tab( );\
l l l l l l l.
   s/(\s\+)/(,)/g
   $a\
.TE
'

The essential boilerplate of the tbl boils down to the following:
a) Mandatory .TS for the start of table
b) data delimiters using    tab(delim_char);
c) columnar publishing: l -> left-justified, r-> right justified,
    c->center-justified, & n-numeric col. Their number must match
    the data cols.
e) Mandatory .TE for the end of table

f) pass on the o/p of tbl to nroff and that's all there's to this utility.

Método-2: Perl

Esse método determina as larguras máximas por campo e, em seguida, o uso dessa informação gera dinamicamente o especificador de formato printf. Este método dará o menor espaçamento.

perl -lne '
   tr/\t/ /;
   s/\((\s+)\)/"(" . "+" x length($1) . ")"/eg;
   ($a, @F) = (-1, split);
   s/\((\++)\)/"(" . " " x length($1) . ")"/eg for @F;
   push @A, [@F];
   $a++, length > $maxW[$a] and $maxW[$a] = length for @F;
   END {
      my $fmt = join $", map { "%-${_}s" } @maxW;
      print sprintf $fmt, @$_ for @A;
   }
' temp.txt
    
por 17.03.2017 / 22:54