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!

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!

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

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...