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!

Building Reliable Asset and Identity Frameworks in Splunk ES

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

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...