Splunk Search

Extract data in log event as key value pair

galbrilovich
Explorer

Hi, I am trying to extract data from my logs to display it by time.

My logs look in this form:

2020-09-09 14:45:46.321 finished processing data- sold 5 products: 2(<product1>) 1(<product2>) 2(<product3>).
i want to show it as a timechart when 3 of the products are shown with each of their values:
2 sales for <product1>, 1 for <product2> and 2 for <product3>, how can i do it for each log?
Note: in a log there can be shown n different products.

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try this query.

| makeresults | eval _raw="2020-09-09 14:45:46.321 finished processing data- sold 5 products: 2(<product1>) 1(<product2>) 2(<product3>)."
```Above just defines test data```
| rex max_match=0 "(?<quantity>\d+)\((?<product>[^\)]+)\)[\.\s+]"
| eval combo = mvzip(product, quantity)
| mvexpand combo
| eval combo = split(combo, ",")
| eval product=mvindex(combo, 0), quantity=mvindex(combo,1)
| timechart sum(quantity) as Sales by product

 

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

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Try this query.

| makeresults | eval _raw="2020-09-09 14:45:46.321 finished processing data- sold 5 products: 2(<product1>) 1(<product2>) 2(<product3>)."
```Above just defines test data```
| rex max_match=0 "(?<quantity>\d+)\((?<product>[^\)]+)\)[\.\s+]"
| eval combo = mvzip(product, quantity)
| mvexpand combo
| eval combo = split(combo, ",")
| eval product=mvindex(combo, 0), quantity=mvindex(combo,1)
| timechart sum(quantity) as Sales by product

 

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

galbrilovich
Explorer

thank you very mush, it works! 🎉

0 Karma
Get Updates on the Splunk Community!

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...