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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Vibe-coding, AI, and Splunkcraft: Highlights from the .conf26 Builder Bar

If you stopped by the Builder Bar at .conf26, thank you! This year, we brought ...

Thanks for the Memories: .conf26 Took Learning to New Heights

Thank you, Splunk Community, for making .conf26 in Denver one for the books. From packed Splunk University ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...