Splunk Search

Need regex to extract specific data

ninadbhaskarwar
Path Finder

I need a regex to get the output as below -

Input
/ABCD/Safe+Alert+-+ABCD+failure Date: Jun 01,2017
/ABCD / Safe +Alert+-+Xyjw%28s%29+not+working Date: Jun 21,2017

Output
ABCD failure

Xyjw not working

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

Try like this (run anywhere sample, replace first 2 line with your search, and update the field names per yours)

| gentimes start=-1 | eval temp="/ABCD/Safe+Alert+-+ABCD+failure Date: Jun 01,2017##/ABCD / Safe +Alert+-+Xyjw%28s%29+not+working Date: Jun 21,2017" | table temp | makemv temp delim="##" | mvexpand temp 
| eval temp=urldecode(temp) | rex field=temp "Alert\s*-\s*(?<YourField>[^\:]+)"

Updated Answer

| gentimes start=-1 | eval temp="/ABCD/Safe+Alert+-+ABCD+failure Date: Jun 01,2017##/ABCD / Safe +Alert+-+Xyjw%28s%29+not+working Date: Jun 21,2017" | table temp | makemv temp delim="##" | mvexpand temp 
| eval temp=urldecode(temp) | rex field=temp "Alert\s*-\s*(?<YourField>.+)\sDate\:"

View solution in original post

woodcock
Esteemed Legend

Like this:

|makeresults |eval raw="/ABCD/Safe+Alert+-+ABCD+failure Date: Jun 01,2017
/ABCD / Safe +Alert+-+Xyjw%28s%29+not+working Date: Jun 21,2017"
| makemv delim="
" raw
| mvexpand raw
| rename raw AS _raw

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| eval output=_raw
| rex field=output mode=sed "s%^/([^/]+)/(?:[^+]*\+){4}(.*) Date.*$%\1 \2% s/\+/ /g"
0 Karma

ninadbhaskarwar
Path Finder

Hi I have already tried your solution but output for second line is

"ABCD not working" where as I was expecting "Xyjw not working"

0 Karma

woodcock
Esteemed Legend

ARGH! I grabbed the wrong ABCD! I will update; hang on...

0 Karma

somesoni2
Revered Legend

Try like this (run anywhere sample, replace first 2 line with your search, and update the field names per yours)

| gentimes start=-1 | eval temp="/ABCD/Safe+Alert+-+ABCD+failure Date: Jun 01,2017##/ABCD / Safe +Alert+-+Xyjw%28s%29+not+working Date: Jun 21,2017" | table temp | makemv temp delim="##" | mvexpand temp 
| eval temp=urldecode(temp) | rex field=temp "Alert\s*-\s*(?<YourField>[^\:]+)"

Updated Answer

| gentimes start=-1 | eval temp="/ABCD/Safe+Alert+-+ABCD+failure Date: Jun 01,2017##/ABCD / Safe +Alert+-+Xyjw%28s%29+not+working Date: Jun 21,2017" | table temp | makemv temp delim="##" | mvexpand temp 
| eval temp=urldecode(temp) | rex field=temp "Alert\s*-\s*(?<YourField>.+)\sDate\:"

ninadbhaskarwar
Path Finder

Output is "ABCD failure Date", I need output without "Date", any suggestion?

0 Karma

somesoni2
Revered Legend

Try the updated answer.

0 Karma

woodcock
Esteemed Legend

Try the updated answer by @somesoni2 😆

0 Karma

woodcock
Esteemed Legend

Try my answer.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...