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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

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