Splunk Search

Extracting values from a field

ibekacyril
Explorer

I have 2 fields like these:

For Field 1:
type=Intelligence

Field 2:
[abcd=[type=High] [Number=3309934] ]

I know I can search by type but there is another field named also named type so if I do

| ...stats count by type

I would get:

Intelligence

How do I specifically extract High from Field 2 (Typing High in the search is not an option because you could have type=Small

Also, using this code:

| ...stats count by abcd

produces : type=High

I only want to see High and not "type="
If you can provide a workable solution either using rex and eval or another code, it would be appreciated.

Thanks in advance

Tags (3)
0 Karma
1 Solution

lguinn2
Legend

Try this:

yoursearchhere
| rex field=abcd "=\[type=(?<new_type>.*?)\]"
| stats count by new_type
| rename new_type as type

This should give you a field named "new_type." It is best if you pick a different field name, otherwise Splunk will merge all the field definitions. I renamed it at the end. This also assumes that what you want is part of the existing field "abcd".

View solution in original post

chimell
Motivator

Hi
try this search code

............................. | rex  field=_raw  "/[abcd/=/[type/=(?<Type>[^\/]]+)" | stats count by Type
0 Karma

ibekacyril
Explorer

Thanks for your help

0 Karma

lguinn2
Legend

Try this:

yoursearchhere
| rex field=abcd "=\[type=(?<new_type>.*?)\]"
| stats count by new_type
| rename new_type as type

This should give you a field named "new_type." It is best if you pick a different field name, otherwise Splunk will merge all the field definitions. I renamed it at the end. This also assumes that what you want is part of the existing field "abcd".

lguinn2
Legend

If the above doesn't work, try this:

 yoursearchhere
 | rex  "=\[type=(?<new_type>.*?)\]"
 | stats count by new_type
 | rename new_type as type

or this

 yoursearchhere
 | rex  "\=\[type\=(?<new_type>.*?)\]"
 | stats count by new_type
 | rename new_type as type

I did make typo in the original answer, which I have now fixed. It is stats not stat! I still don't see anything wrong witn the original regular expression, but maybe someone else will...

0 Karma

ibekacyril
Explorer

Thanks for your help

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