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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...