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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...