Splunk Search

regular expression to extract lines of text between two different texts

satya671
Explorer

suppose i had data like below field="_raw"

afadfadfadf

afadsfagafg

adfafafa

string1 .........

afjal;dkfhao ilhaf

ajkf;haldghag;lakg

akuhfajkdhfalkfha;

auhaghkajdgakg

jkalfagafg

string2.........

afdasdgadfas

**bleep**adgafgafgaf

agfgertfergreg

And i want to extract the data in between string1 and string2

 

Labels (1)
0 Karma
1 Solution

venkatasri
SplunkTrust
SplunkTrust

Hi @satya671 

| makeresults 
| eval _raw="afadfadfadf
afadsfagafg

adfafafa

string1 .........

afjal;dkfhao ilhaf

ajkf;haldghag;lakg

akuhfajkdhfalkfha;

auhaghkajdgakg

jkalfagafg

string2.........

afdasdgadfas" 
| rex "string1(?<extracted>(.|\n)*?)string2" 
| table extracted

 

You could try this.

 

View solution in original post

venkatasri
SplunkTrust
SplunkTrust

Hi @satya671 

| makeresults 
| eval _raw="afadfadfadf
afadsfagafg

adfafafa

string1 .........

afjal;dkfhao ilhaf

ajkf;haldghag;lakg

akuhfajkdhfalkfha;

auhaghkajdgakg

jkalfagafg

string2.........

afdasdgadfas" 
| rex "string1(?<extracted>(.|\n)*?)string2" 
| table extracted

 

You could try this.

 

satya671
Explorer

Thanks @venkatasri  it's working as expected 🙂

0 Karma
Get Updates on the Splunk Community!

What the End of Support for Splunk Add-on Builder Means for You

Hello Splunk Community! We want to share an important update regarding the future of the Splunk Add-on Builder ...

Solve, Learn, Repeat: New Puzzle Channel Now Live

Welcome to the Splunk Puzzle PlaygroundIf you are anything like me, you love to solve problems, and what ...

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...