Sponsored Content
Top Forums Shell Programming and Scripting Find pattern; grep n lines before and after Post 302992455 by vasil on Saturday 25th of February 2017 04:56:44 AM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 07:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy