Splunk Dev

How do I extract a field from the _raw data

danielsan
New Member

Hi guys,

Tried my best googling an answer but have not been able to find something that fits my requirement.

I have the following raw_data:

... \"number_of_goods\":10,\"number_of_locations\":5, ...

How do I create a field called number_of_goods and number_of_locations where the value is 10 and 5?

Many thanks in advance!

Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try the rex command. The backslashes are needed to escape the backslashes and quotes in your data.

<your search> | rex "number_of_goods\\\\\":(?<numberOfGoods>\d+),\\\\\"number_of_locations\\\\\":(?<numberOfLocations>\d+)" | ...
---
If this reply helps you, Karma would be appreciated.

danielsan
New Member

It works, you really saved my day. I have one follow-up question though. I'm trying to extract a similar field but it has a decimal value, e.g. 0.25 and with the rex example I got from you, I only get the first digit before the decimal and I can't figure out how to get the full value.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The regex for a floating point number is \d+\.\d+.

---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

If your problem is resolved, please accept the answer to help future readers.

---
If this reply helps you, Karma would be appreciated.
0 Karma

FrankVl
Ultra Champion

I guess you could also avoid having to mess with those backslashes and escaped quotes, by doing:

| rex "number_of_goods[^:]+:(?<numberOfGoods>\d+),[^\w]+number_of_locations[^:]+:(?<numberOfLocations>\d+)"

https://regex101.com/r/RgxoTh/1

Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...