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!

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...