Splunk Search

How do I extract a field from my raw data using rex command?

tanvi1g
New Member

Hi,

Can someone able to help me please.

I'm very new to using Splunk and most certainly to the rex command and regular expressions, so please bear with.

I'm trying to extract an accountId field from my raw data which is in the following format { "accountId":"C12345678" }

Could someone possibly tell me please how I may strip the actual accountId number out of this line.

Many thanks and kind regards

Tanvi

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

Is your raw data in JSON format (hard to tell from the snippet). If it is, Splunk will do the field extraction for you.

0 Karma

tanvi1g
New Member

No, it's apache log

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this.

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

cpetterborg
SplunkTrust
SplunkTrust

I would have done it slightly differently (in case there were non-\w characters in the accountId):

... | rex "accountId\":\"(?<accountId>[^\"]+)" | ...

tanvi1g
New Member

Thanks. I will try this.

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