如何将文本文件格式化为所需的输出

如何将文本文件格式化为所需的输出

文本文件:

 ***** Connected to QBBSC01 *****  

MO  
RXOTG-0


DEV              DCP  APUSAGE  APSTATE           64K  TEI  
RBLT2-161        1    UNCONC   SPEECH/DATA       YES  
RBLT2-162        2    UNDEF    IDLE              YES  
RBLT2-163        3    UNCONC   SPEECH/DATA       YES  
RBLT2-164        4    UNDEF    IDLE              YES


***** Disconnected from QBBSC01 *****

***** Connected to QBBSC04 *****

MO  
RXOTG-23  

DEV            DCP  APUSAGE  APSTATE           64K  TEI  
RBLT2-161        1  UNCONC   SPEECH/DATA       YES  
RBLT2-162        2  UNDEF    IDLE              YES  
RBLT2-163        3  UNCONC   SPEECH/DATA       YES  
RBLT2-164        4  UNDEF    IDLE              YES  
RBLT2-165        5  UNCONC   SPEECH/DATA       YES  
RBLT2-166        6  UNCONC   SPEECH/DATA       YES  
RBLT2-167        7  UNDEF    IDLE              NO  
RBLT2-168        8  UNCONC   SPEECH/DATA       NO  


***** Disconnected from QBBSC04 *****  

***** Connected to QBBSC05 *****  

MO  
RXOTG-7  

DEV            DCP  APUSAGE  APSTATE           64K  TEI  
RBLT2-161        1  UNCONC   SPEECH/DATA       YES  
RBLT2-162        2  UNDEF    IDLE              YES  
RBLT2-163        3  UNCONC   SPEECH/DATA       YES  
RBLT2-164        4  UNDEF    IDLE              YES  
RBLT2-165        5  UNCONC   SPEECH/DATA       YES  
RBLT2-166        6  UNCONC   SPEECH/DATA       YES  


***** Disconnected from QBBSC05 *****  

期望的输出:

NE      MO      DEV            DCP  APUSAGE  APSTATE           64K TEI  
QBBSC01 RXOTG-0 RBLT2-161        1  UNCONC   SPEECH/DATA       YES  
QBBSC01 RXOTG-0 RBLT2-162        2  UNDEF    IDLE              YES  
QBBSC01 RXOTG-0 RBLT2-163        3  UNCONC   SPEECH/DATA       YES  
QBBSC01 RXOTG-0 RBLT2-164        4  UNDEF    IDLE              YES  


NE      MO       DEV            DCP  APUSAGE  APSTATE           64K TEI  
QBBSC04 RXOTG-23 RBLT2-161        1  UNCONC   SPEECH/DATA       YES  
QBBSC04 RXOTG-23 RBLT2-162        2  UNDEF    IDLE              YES    
QBBSC04 RXOTG-23 RBLT2-163        3  UNCONC   SPEECH/DATA       YES    
QBBSC04 RXOTG-23 RBLT2-164        4  UNDEF    IDLE              YES  
QBBSC04 RXOTG-23 RBLT2-165        5  UNCONC   SPEECH/DATA       YES  
QBBSC04 RXOTG-23 RBLT2-166        6  UNCONC   SPEECH/DATA       YES  
QBBSC04 RXOTG-23 RBLT2-167        7  UNDEF    IDLE              NO  
QBBSC04 RXOTG-23 RBLT2-168        8  UNCONC   SPEECH/DATA       NO  


NE      MO      DEV            DCP  APUSAGE  APSTATE           64K  TEI  
QBBSCO5 RXOTG-7 RBLT2-161        1  UNCONC   SPEECH/DATA       YES  
QBBSCO5 RXOTG-7 RBLT2-162        2  UNDEF    IDLE              YES  
QBBSCO5 RXOTG-7 RBLT2-163        3  UNCONC   SPEECH/DATA       YES  
QBBSCO5 RXOTG-7 RBLT2-164        4  UNDEF    IDLE              YES  
QBBSCO5 RXOTG-7 RBLT2-165        5  UNCONC   SPEECH/DATA       YES  
QBBSCO5 RXOTG-7 RBLT2-166        6  UNCONC   SPEECH/DATA       YES  

请不要考虑行号。

答案1

从问题中尚不清楚各个领域可能有何不同。但对于您的示例,一个简单的awk程序可能如下所示:

/Connected/ { NE=$4 }
/RXOTG/     { MO=$1 }
/DEV/       { printf "\n\nNE      %*s %s\n", -length(MO), "MO", $0 }
/RBLT2/     { print NE, MO, $0 }

相关内容