Splunk Search

How to extract three separate values from my sample event into a single field?

splunker9999
Path Finder

Hi,

I have events with the below format:

"phone":{"areaCode":"732","prefix":"986","lineNumber":"0245",

Is there a way we could extract all the above values to a single field called phone as 732-986-0245?

Can someone please help us in this?

Thanks
Sarath

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

Just create a calculated field for the sourcetype (under Settings->Fields) and use the eval expression phone.areaCode."-".phone.prefix."-".phone.lineNumber
Make sure you elevate to app or system visibility and the field will show up whenever you search for that sourcetype.
This, of course, assumes that you have valid JSON events and not just the fragment you have shown us...

sundareshr
Legend

Try this

... | rex "Code.{3}(?<ac>\d{3})".*\b(?<pre>\d{3})\b.*\b(?<no>\d{4})" | eval phone=ac."-".pre."-".no

splunker9999
Path Finder

Correcting my question !!

we actually have the value as below in our events and we need to extract from events
Hi,

I have a event with below format

"phone":{"areaCode":"732","prefix":"986","lineNumber":"0245",

Is there a way, we could extract all the above to a single field called phone as 732-986-0245?

Can someone please help us in this?

Thanks
Sarath

0 Karma

somesoni2
Revered Legend

Do you have json formatted events and right now you get 3 fields phone.areaCode, phone.prefix and phone.lineNumber OR you just get a field say phone and that field contains the whole string "phone":{"areaCode":"732","prefix":"986","lineNumber":"0245"?

0 Karma
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL  The Splunk AI Assistant for SPL ...

Buttercup Games: Further Dashboarding Techniques (Part 5)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Customers Increasingly Choose Splunk for Observability

For the second year in a row, Splunk was recognized as a Leader in the 2024 Gartner® Magic Quadrant™ for ...