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!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...