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

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 03:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy