Splunk Search

Dynamically extract the field at nth position

harshal_chakran
Builder

Hi,
I have a log, where I want to extract some specific value. My log file sample as follows:

111,0,0,0,0,0,0,0,0,12,13,14,15,16,17,18

222,0,0,0,0,0,0,0,0,22,23,24,25,26,27,28

333,0,0,0,0,0,0,0,0,32,33,34,35,36,37,38

I want to extract the field at 12th position i.e "14" from row1, "24 from row2" and "34" from row3, and show them in list output.
I have used rex method, where I have defined "\d+" 12th times to get the value from list which makes the search query very large. Is it possible that I can dynamically assign a variable to the nth position, instead of writing "\d+" n times?

Tags (2)
0 Karma
1 Solution

gfuente
Motivator

You can do it this way

(\d+,){11}(?< field >\d+)

*Remove the blanks before and after the brackets

Regards

View solution in original post

gfuente
Motivator

You can do it this way

(\d+,){11}(?< field >\d+)

*Remove the blanks before and after the brackets

Regards

Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...