Splunk Search

Extract fields from non-JSON formatted data

Matthew86
Explorer

Hi Guys, 

Hope you can help me out. 

Consider the following data in Splunk: 

 

 

{ 
   attrs: { 
     account: 85859303
     version: 1.3848
   }
   line: { 
     application_version: 1.94949303
     message: Event with key 84js9393: {"entity": {"customer_id": "K123456", "order_id": "Sjd49493-93nd-9494-jdjd-mskaldjfhfhh", "collection_id": "djdis939-9398-9488-j939-md839md93000", "issuer_id": null}}
     thread: springfield
     timestamp: 2021-12-21 19:30:52,123
   }
}

 

 

 

I would like to extract the order_id and use it in my search: 

order_id=Sjd49493-93nd-9494-jdjd-mskaldjfhfhh

Hope someone can help or point me in the right direction.

Cheers! 

Matthew 

Labels (3)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

It's easy with rex

... | rex "order_id\\\":\s\\\"(?<order_id>[^\\\"]+)"
...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

It's easy with rex

... | rex "order_id\\\":\s\\\"(?<order_id>[^\\\"]+)"
...
---
If this reply helps you, Karma would be appreciated.

Matthew86
Explorer

Hi richgalloway, Thanks for you reply.

Unfortunately when I for example try to table the results I do not receive any results. 

For example

Base search ....
| rex "order_id\\\":\s\\\"(?<order_id>[^\\\"]+)"
| table order_id
0 Karma

Matthew86
Explorer

fixed it:

| rex field=line.message "order_id\\\":\s\\\"(?<order_id>[^\\\"]+)"
| table order_id
Get Updates on the Splunk Community!

2024 Splunk Career Impact Survey | Earn a $20 gift card for participating!

Hear ye, hear ye! The time has come again for Splunk's annual Career Impact Survey!  We need your help by ...

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...