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
SplunkTrust
SplunkTrust

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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...