Splunk Search

How do I edit the regex in my search to extract a part of a string?

kumina
New Member

I have a log:

 BL: | LL: INFO | TS: 1234 | AR: RxC_16.00.37.01 | STORE:  :BROADCAST |
 USER: BROADCAST | HOST: BROADCAST | APPSERVER: rri | MSGID: CINTERFACE
 |SC: [Profile] | MSG: ISP Broadcast Received for

I want to get MSGID-SC (CINTERFACE-Profile) from the string above.

For this i am trying to use rex command:

index=rx_connect "USER: BROADCAST" |rex field=_raw
"MSGID:\s(?<MSGID>[^\|]*)\s\|\SC:\s\[(?<SC>[^\]]*)\]" | eval
someNewField=MSGID."-".SC`

But it is not working. Please suggest further.

0 Karma

chimell
Motivator

Hi kumina

If msgid and sc are not constant , use the max_match option and mvindex command to solve your problem

Try this search code

 index=rx_connect "USER: BROADCAST"|rex field=_raw  max_match=0 "\|\s\w+\:\s(?P<msgid1>[^\|]+)\s"|eval msgid=mvindex(msgid1,7)
|rex field=_raw "\[(?P<sc>[^\|]+)\]"|rex field=_raw "\|\s(?P<field1>[\w]+)\:\sCINTERFACE"|rex field=_raw "\|(?P<field2>[\w]+)\:\s\[Profile]"|eval someNewField = field1."-".field2."  (".msgid."-".sc.")" 
|table msgid sc field1 field2 someNewField

see result
alt text

0 Karma

chimell
Motivator

Hi kumina

Try this search code it works well

 index=rx_connect "USER: BROADCAST" |rex field=_raw "MSGID:\s(?P<msgid>[^\|]+)\s"|rex field=_raw "SC:\s\[(?P<sc>[^\|]+)\]"|rex field=_raw "\|\s(?P<field1>[\w]+)\:\sCINTERFACE"|rex field=_raw "\|(?P<field2>[\w]+)\:\s\[Profile]"|eval someNewField = field1."-".field2."  (".msgid."-".sc.")" |table msgid sc field1 field2 someNewField

Look at the following screen capture

alt text

0 Karma

chimell
Motivator

Thanks too .
Test the second result and think to vote and accept

0 Karma

kumina
New Member

Thanks Chimell....
Now it works

0 Karma

kumina
New Member

Hi,

If value of msgid and sc in above logs is not constant and we want to extract that part then what will be the string

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Your regex has a Typo. Try this:

index=rx_connect "USER: BROADCAST" |rex field=_raw "MSGID:\s(?<msgid>[^\|]+)\s\|SC:\s\[(?<sc>[^\]]*)\]" | eval someNewField = msgid."-".sc

kumina
New Member

Hi,

I am still getting whole logs instead of

MSGID-SC

example:(CINTERFACE-Profile)

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 ...