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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...