Find pattern; grep n lines before and after


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find pattern; grep n lines before and after
# 1  
Old 02-25-2017
Find pattern; grep n lines before and after

Hi,

I need help to grep a specific part of a log file (bold).
Code:
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                                          }
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                                          extensionContainer <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                                          imsi <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                                          _ellipsis <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                                      }
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                                  }
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                              }
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                              returnResultLast <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                              returnError <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                              reject <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                              returnResultNotLast <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                          }
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                      }
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                      abort <Not Present>
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx:                  }
[     13] 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx: }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx: UDT{
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    SGW: VIP_mk_STP1
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    OPC: 996
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    DPC: 7822
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    SLS: 3
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:         Source Address: [Route on: GT] [INC: SSN GT] [ SSN: 8 GT: '38977000103' (4.0.1.4)]
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:    Destination Address: [Route on: GT] [INC: SSN GT] [ SSN: 8 GT: '38977000301' (4.0.1.4)]
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:              Hop Count: 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 62 68 48 04 85 00 03 17 6b 1a 28 18 06 07 00 11 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 86 05 01 01 01 a0 0d 60 0b a1 09 06 07 04 00 00 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 01 00 15 02 6c 44 a1 42 02 01 01 02 01 2e 30 3a 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 84 07 91 83 79 07 00 03 f1 82 07 91 83 79 48 40 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 38 f7 04 26 01 8e 09 81 70 38 49 24 f0 00 00 1d 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: d4 b4 7c 1c 6e 83 dc 61 10 5d 5e 26 b7 d3 6c 10 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 3d 0d a2 cb cb e2 70 b8 fd 03 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   TCAP Message{
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Opcode 46 Result: No
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      unidirectional <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      begin = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                          otid = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              85 00 03 17 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                          }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                          dialoguePortion = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              dialogueAsID = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  00 11 86 05 01 01 01
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              dialoguePDU = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  dialogueRequest = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      protocol_version <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      app_context = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          name = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              7 Bytes
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              04 00 00 01 00 15 02 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      userInfoExt <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  dialogueResponse <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  dialogueAbort <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                          }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                          components = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              invoke = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  invokeID = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      1
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  linkedID <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  operationCode = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      46
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  parameter = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      30 3a 84 07 91 83 79 07 00 03 f1 82 07 91 83 79 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      48 40 38 f7 04 26 01 8e 09 81 70 38 49 24 f0 00 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      00 1d d4 b4 7c 1c 6e 83 dc 61 10 5d 5e 26 b7 d3 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      6c 10 3d 0d a2 cb cb e2 70 b8 fd 03 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                  
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      MO_ForwardSM_Arg = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          sm_RP_DA = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              imsi <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              lmsi <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              roamingNumber <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              serviceCentreAddressDA = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  '1.1.38977000301'
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              noSM_RP_DA <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          sm_RP_OA = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              msisdn = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  '1.1.38978404837'
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              serviceCentreAddressOA <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              noSM_RP_OA <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          sm_RP_UI = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              38 Bytes
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              01 8e 09 81 70 38 49 24 f0 00 00 1d d4 b4 7c 1c 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              6e 83 dc 61 10 5d 5e 26 b7 d3 6c 10 3d 0d a2 cb 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              cb e2 70 b8 fd 03 
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              sms-submit = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-rd   : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-vpf  : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-srr  : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-udhi : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-rp   : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-mr   : 142
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-da   : 0.1.078394420
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-pid  : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-pid  : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-dcs  : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-vp   : 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                                  tp-udl  : 29
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                              }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          extensionContainer <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          imsi <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                          _ellipsis <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                      }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                                  }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              returnResultLast <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              returnError <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              reject <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                              returnResultNotLast <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                          }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      end <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      kontinue <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      abort <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                  }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx: }
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx: UDT{
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    SGW: VIP_mk_STP1
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    OPC: 996
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    DPC: 7822
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                    SLS: 3
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:         Source Address: [Route on: GT] [INC: SSN GT] [ SSN: 8 GT: '38977000103' (4.0.1.4)]
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:    Destination Address: [Route on: GT] [INC: SSN GT] [ SSN: 8 GT: '38977000301' (4.0.1.4)]
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:              Hop Count: 0
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 62 68 48 04 85 00 03 17 6b 1a 28 18 06 07 00 11
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 86 05 01 01 01 a0 0d 60 0b a1 09 06 07 04 00 00
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 01 00 15 02 6c 44 a1 42 02 01 01 02 01 2e 30 3a
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 84 07 91 83 79 07 00 03 f1 82 07 91 83 79 48 40
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 38 f7 04 26 01 8e 09 81 70 38 49 24 f0 00 00 1d
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: d4 b4 7c 1c 6e 83 dc 61 10 5d 5e 26 b7 d3 6c 10
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Data: 3d 0d a2 cb cb e2 70 b8 fd 03
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   TCAP Message{
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                   Opcode 46 Result: No
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      unidirectional <Not Present>
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                      begin = {
[     14] 24/2/2017-16:57:17.097 frosti-2 M3UA-Rx:                          otid = {

1. Search the file for pattern tp-da : 0.1.078394420
2. Print all lines before tp-da : 0.1.078394420 till first M3UA-Rx: UDT{ match including.
3. Print all lines after tp-da : 0.1.078394420 till first M3UA-Rx: } match including.

Any help is greatly appreciated.

Last edited by vasil; 02-25-2017 at 06:05 AM..
# 2  
Old 02-25-2017
The non-interactive text editors are great for this kind of thing. Either of the following should work on any system with a POSIX conforming ed or ex:
Code:
ed -s file <<-"EOF"
	g/tp-da *: *0[.]1[.]078394420/?UDT{?,/M3UA-Rx: }/p
	q
EOF

Code:
ex -s -c 'g/tp-da *: *0[.]1[.]078394420/?UDT{?,/M3UA-Rx: }/p
	  q' file

Although not required by POSIX, some systems will allow that ex command to be written with two -c options on one line:
Code:
ex -s -c 'g/tp-da *: *0[.]1[.]078394420/?UDT{?,/M3UA-Rx: }/p' -c 'q' file

These 3 Users Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-25-2017
30 minutes after my post. Thank you Don for the great answer.
Tested the last command and works.
# 4  
Old 02-25-2017
Alternatives, simple:
Code:
awk '1; /M3UA-Rx: }/{print x}' infile | awk '/tp-da. *: 0\.1\.078394420/' RS=

single awk:
Code:
awk '/M3UA-Rx: UDT{/{r=$0; next} {r=r RS $0} /tp-da. *: 0\.1\.078394420/{f=1} /M3UA-Rx: }/{if(f)print r; f=r=x}' file

sed:
Code:
sed -n '/M3UA-Rx: UDT{/{h;n;}; H; /M3UA-Rx: }/{g; /tp-da. *: 0\.1\.078394420/p;}' file

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 02-26-2017
Thanks Scrutinizer

Using combination from Don's and yours command, can you advice how to use a variable in sed?
For example:
Code:
FILE=ss7;sed -n '/M3UA-Rx: UDT{/{h;n;}; H; /M3UA-Rx: }/{g; /M3UA-Rx.* *01 01 06 a6.*/p;}' $FILE
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx: UDT{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		      OPC: 2445
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		      DPC: 2085
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		      SLS: 13
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:	   Source Address: [Route on: GT] [INC:	SSN GT]	[ SSN: 6 GT: '85290240832' (4.0.1.4)]
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:    Destination Address: [Route on: GT] [INC:	SSN GT]	[ SSN: 8 GT: '85290240960' (4.0.1.4)]
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		Hop Count: 0
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 64 51 49 04 01 01 06	a6 6b 26 28 24 06 07 00	11 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 86 05 01 01 01 a0 19	61 17 a1 09 06 07 04 00	00 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 01 00 14 02 a2 03 02	01 00 a3 05 a1 03 02 01	00 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 6c 21 a2 1f 02 01 01	30 1a 02 01 2d 30 15 04	08 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 54 04 30 70 00 00 40	f9 a0 09 81 07 91 58 92	20 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 04 08 f1 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     TCAP Message{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Opcode 45 Result: Yes
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			unidirectional <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			begin <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			end = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    dtid = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				01 01 06 a6
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    dialoguePortion = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				dialogueAsID = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    00 11 86 05	01 01 01
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				dialoguePDU = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    dialogueRequest <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    dialogueResponse = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					protocol_version <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					app_context = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    name = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						7 Bytes
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						04 00 00 01 00 14 02 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					result = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    enuum = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						0 (accepted)
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					result_source_diagnostic = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    dialogue_service_user = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						enuum =	{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    0 (dsu_null)
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    dialogue_service_provider <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					userInfoExt <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    dialogueAbort <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    components = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				invoke <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				returnResultLast = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    invokeID = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					1
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    result = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					operationCode =	{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    45
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					parameter = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    30 15 04 08	54 04 30 70 00 00 40 f9	a0 09 81 07 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    91 58 92 20	04 08 f1 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		    
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    RoutingInfoForSM_Res = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						imsi = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    '454003070000049'
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						locationInfoWithLMSI = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    networkNode_Number = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:							'1.1.85290240801'
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    lmsi <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    extensionContainer <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    gprsNodeIndicator <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    additional_Number <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    _ellipsis <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						extensionContainer <Not	Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						_ellipsis <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				returnError <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				reject <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				returnResultNotLast <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			kontinue <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			abort <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx: }


I would like to change 01 01 06 a6 with variable:

Code:
FILE=ss7;OTID=$(ex -s -c 'g/SSN: 6 GT: .85290985144.*/?UDT{?,/M3UA-Tx: }/p'  -c 'q' $FILE | awk 'f{print;f=0} /otid/{f=1}' | sed -re 's,\s+, ,g' | cut -d ' ' -f 6-); echo $OTID
01 01 06 a6


The below gives me nothing:
Code:
FILE=ss7;OTID=$(ex -s -c 'g/SSN: 6 GT: .85290985144.*/?UDT{?,/M3UA-Tx: }/p'  -c 'q' $FILE | awk 'f{print;f=0} /otid/{f=1}' | sed -re 's,\s+, ,g' | cut -d ' ' -f 6-); sed -n '/M3UA-Rx: UDT{/{h;n;}; H; /M3UA-Rx: }/{g; /M3UA-Rx.* *$OTID.*/p;}' $FILE

How to expand $OTID variable in the sed expression?

Last edited by vasil; 02-26-2017 at 03:51 AM..
# 6  
Old 02-26-2017
Please explain to us what you are trying to do. If you are going to use awk, there is probably no need to also use ex, cut, and two invocations of sed. I'm almost positive that the REs you are using in your search patterns are not doing what you think they are doing (and could match strings that you don't intend for them to match).

An immediate problem is that shell variables are not expanded inside single quoted strings. You could try, using double quotes (") instead of single quotes (') around the operand in the last sed invocation in your command line and it might work; but unless you intend for all of the <period>s in your REs to match any character (not just a <period>), your command line might not work reliably.
# 7  
Old 02-26-2017
Hi Don,

My initial post was to get an idea how to extract different parts of a huge log file.
Thanks to yours and Scrutinizer advises I'm trying to prepare a script to extract all the parts i'm interested in at once. The parts are connected by id string ("otid" or "dtid").

For example the below 2 parts are connected by "otid/dtid" string.

Code:
FILE=ss7;ex -s -c 'g/SSN: 6 GT: .85290985144.*/?UDT{?,/M3UA-Tx: }/p'  -c 'q'  $FILE

[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx: UDT{
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                    SGW: TPC-iSPS11-32
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                    OPC: 2085
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                    DPC: 2444
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                    SLS: 9
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:         Source Address: [Route on: GT] [INC: SSN GT] [ SSN: 8 GT: '85290240960' (4.0.1.4)]
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:    Destination Address: [Route on: GT] [INC: SSN GT] [ SSN: 6 GT: '85290985144' (4.0.1.4)]
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:              Hop Count: 0
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   Data: 62 43 48 04 01 01 06 a6 6b 1a 28 18 06 07 00 11 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   Data: 86 05 01 01 01 a0 0d 60 0b a1 09 06 07 04 00 00 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   Data: 01 00 14 02 6c 1f a1 1d 02 01 01 02 01 2d 30 15 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   Data: 80 07 91 58 92 90 58 41 f4 81 01 ff 82 07 91 58 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   Data: 92 20 04 69 f0 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   TCAP Message{
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   Opcode 45 Result: No
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                      unidirectional <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                      begin = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                          otid = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              01 01 06 a6 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                          }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                          dialoguePortion = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              dialogueAsID = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  00 11 86 05 01 01 01
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              dialoguePDU = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  dialogueRequest = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      protocol_version <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      app_context = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          name = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                              7 Bytes
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                              04 00 00 01 00 14 02 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      userInfoExt <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  dialogueResponse <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  dialogueAbort <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                          }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                          components = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              invoke = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  invokeID = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      1
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  linkedID <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  operationCode = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      45
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  parameter = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      30 15 80 07 91 58 92 90 58 41 f4 81 01 ff 82 07 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      91 58 92 20 04 69 f0 
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                  
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      RoutingInfoForSM_Arg = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          msisdn = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                              '1.1.85290985144'
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          sm_RP_PRI = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                              True
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          serviceCentreAddress = {
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                              '1.1.85290240960'
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          __v1_only_cug_interlock <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          __v1_only_teleserviceCode <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          extensionContainer <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          gprsSupportIndicator <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          sm_RP_MTI <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          sm_RP_SMEA <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                          _ellipsis <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                      }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                                  }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              returnResultLast <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              returnError <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              reject <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                              returnResultNotLast <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                          }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                      }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                      end <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                      kontinue <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                      abort <Not Present>
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                  }
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx: }

Code:
FILE=ss7;sed -n "/M3UA-Rx: UDT{/{h;n;}; H; /M3UA-Rx: }/{g; /M3UA-Rx.* *01 01 06 a6.*/p;}" $FILE

[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx: UDT{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		      OPC: 2445
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		      DPC: 2085
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		      SLS: 13
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:	   Source Address: [Route on: GT] [INC:	SSN GT]	[ SSN: 6 GT: '85290240832' (4.0.1.4)]
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:    Destination Address: [Route on: GT] [INC:	SSN GT]	[ SSN: 8 GT: '85290240960' (4.0.1.4)]
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		Hop Count: 0
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 64 51 49 04 01 01 06	a6 6b 26 28 24 06 07 00	11 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 86 05 01 01 01 a0 19	61 17 a1 09 06 07 04 00	00 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 01 00 14 02 a2 03 02	01 00 a3 05 a1 03 02 01	00 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 6c 21 a2 1f 02 01 01	30 1a 02 01 2d 30 15 04	08 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 54 04 30 70 00 00 40	f9 a0 09 81 07 91 58 92	20 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Data: 04 08 f1 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     TCAP Message{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		     Opcode 45 Result: Yes
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			unidirectional <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			begin <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			end = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    dtid = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				01 01 06 a6
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    dialoguePortion = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				dialogueAsID = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    00 11 86 05	01 01 01
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				dialoguePDU = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    dialogueRequest <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    dialogueResponse = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					protocol_version <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					app_context = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    name = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						7 Bytes
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						04 00 00 01 00 14 02 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					result = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    enuum = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						0 (accepted)
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					result_source_diagnostic = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    dialogue_service_user = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						enuum =	{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    0 (dsu_null)
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    dialogue_service_provider <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					userInfoExt <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    dialogueAbort <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    components = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				invoke <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				returnResultLast = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    invokeID = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					1
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    result = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					operationCode =	{
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    45
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					parameter = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    30 15 04 08	54 04 30 70 00 00 40 f9	a0 09 81 07 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    91 58 92 20	04 08 f1 
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		    
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    RoutingInfoForSM_Res = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						imsi = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    '454003070000049'
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						locationInfoWithLMSI = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    networkNode_Number = {
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:							'1.1.85290240801'
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    lmsi <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    extensionContainer <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    gprsNodeIndicator <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    additional_Number <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						    _ellipsis <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						extensionContainer <Not	Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:						_ellipsis <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:					}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				returnError <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				reject <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:				returnResultNotLast <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			}
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			kontinue <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:			abort <Not Present>
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx:		    }
[     13] 25/2/2017-19:02:07.185 frosti-3 M3UA-Rx: }

What I'm trying to do is after printing the first part, to filter "otid" string 01 01 06 a6

Code:
For test:

FILE=ss7; OTID=$(ex -s -c 'g/SSN: 6 GT: .85290985144.*/?UDT{?,/M3UA-Tx: }/p'  -c 'q' ss7 | awk 'f{print;f=0} /otid/{f=1}' | sed -re 's,\s+, ,g' | cut -d ' ' -f 6-); echo $OTID
01 01 06 a6

save it as variable and use it in the command for the second part.

Code:
FILE=ss7

#Print first part
ex -s -c 'g/SSN: 6 GT: .85290985144.*/?UDT{?,/M3UA-Tx: }/p'  -c 'q'  $FILE

#Extract otid from first part
OTID=$(ex -s -c 'g/SSN: 6 GT: .85290985144.*/?UDT{?,/M3UA-Tx: }/p'  -c 'q' ss7 | awk 'f{print;f=0} /otid/{f=1}' | sed -re 's,\s+, ,g' | cut -d ' ' -f 6-)

#Use otid variable to search for the second part
sed -n '/M3UA-Rx: UDT{/{h;n;}; H; /M3UA-Rx: }/{g; /M3UA-Rx.* *$OTID.*/p;}' $FILE


Last edited by vasil; 02-26-2017 at 05:13 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep all lines with the pattern .sh

Linux version : Oracle Linux 6.5 Shell : bash In the the below text file (someString.text), I want to grep all lines with .sh in it. ie. Only the lines mysript.sh and anotherscript.sh should be returned. My below attempts failed. I gather that in regular expression world, dot (.) is the... (3 Replies)
Discussion started by: John K
3 Replies

2. Shell Programming and Scripting

Grep pattern only and surrounding lines

Hello, I am trying to grep search a pattern and a line before it. cat input >record1 hello1hello2hellonhello3 >record2 helloohello1hello2hello3 When I use, grep with -o option and either of -A/B/C options, I still can't see lines before or after the pattern. But the exact pattern is... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

3. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

4. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

5. Shell Programming and Scripting

Grep lines before a pattern having some other pattern

Hi All, I am trying to fetch lines before a pattern, I got to know about -B flag in grep but we have to pass the number to get those lines before some pattern say (X), now what if I want to get line/s with some other pattern say (Y) before X pattern? How to get about it? please help. Input:... (5 Replies)
Discussion started by: dips_ag
5 Replies

6. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

7. Shell Programming and Scripting

grep: get last 3 lines containing PATTERN from many files

Hi all, I am looking for a quick solution for this: I have many log files of an iterative program, and I would like to display the parameters of the last three iteration from each of those files. Relevant lines have the keyword: ITER I am using: tac ~/modeling*/fitting.log | grep -m 3 -e... (2 Replies)
Discussion started by: pnemeth
2 Replies

8. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

9. UNIX for Dummies Questions & Answers

Grep with 8 lines before and after pattern.

OK. I have a file I'd like to be able to grep, but on top of returning the line where the pattern matches, I'd like to be able to get the previous 8 lines and the following 8 lines. Is there a way to do this? (2 Replies)
Discussion started by: mrwatkin
2 Replies

10. Solaris

How to grep (say)last-3 and next-3 lines of Desired Pattern

Hi All, OS-Type=Sun-OS 5.8 Sparc9 Processor Can I grep the previous 4 lines and next 4 lines of a matched pattern(context grep)? For example here we need to monitor logs of live traffic.The data obtained from "tail -f LiveTrafficData.log" looks something like this:-... (3 Replies)
Discussion started by: Sujan Banerjee
3 Replies
Login or Register to Ask a Question