0

Text File:

 ***** 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 *****  

Desired Output:

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  

Please do not put line numbers into consideration.

4
  • It's customary (or good manners) to add some wording concerning how you want to achieve this and what you've tried so far.
    – steve
    Sep 10, 2016 at 15:53
  • That right roaima, but I'm beginner with this codes what i have tried so far is somewhat embarrassing believe me, you don't want to see that. Please help.
    – stanlyof
    Sep 10, 2016 at 16:16
  • Please review the formatting of your question - it seems inconsistent. Are some lines - but not all - really prefixed by a > or is that a remnant of earlier formatting attempts? Do the delimiter strings really vary e.g. ***** *Connected versus ***** Connected? Sep 10, 2016 at 20:16
  • Updated...@steeldriver
    – stanlyof
    Sep 10, 2016 at 20:34

1 Answer 1

1

It is not quite clear from the questions how the various fields may vary. But for your example a simple awk program could look like this:

/Connected/ { NE=$4 }
/RXOTG/     { MO=$1 }
/DEV/       { printf "\n\nNE      %*s %s\n", -length(MO), "MO", $0 }
/RBLT2/     { print NE, MO, $0 }
2
  • It does get a bit less straightforward if the RXOTGs and RBLTs don't always have such a distinct format. I might suggest using /^DEV/ etc. though. Extra cookie points for %*s :)
    – ilkkachu
    Sep 12, 2016 at 12:10
  • Yes, the code wasn't meant as the final solution, more of a draft. I imagine one might have t tweak the patterns, but that requires a more detailed knowledge about the variation of the input. Thanks for the extra cookie points! :) Sep 12, 2016 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.