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!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...