Splunk Search

assigning repeating / rolling sequential field

ChrisCLewis
Communicator

I am looking to have a new field that will assign a reference to each, this reference will be sequential and will repeat.

e.g.
Record . . . ref
1, 6, 11 . . . 1
2, 7, 12 . . . 2
but the number of records is going to change as will the number for the first record so it needs to work on the order of the records.
I had thought stream stats but can't see a way to make it work.

Many thanks for any help

0 Karma
1 Solution

to4kawa
Ultra Champion
| makeresults count=5000
| streamstats current=f count
| eval ref = "a ref of ".((count % 5) + 1)

Hi, @ChrisCLewis
My machine can't work with count=500000000
but , your machine will work.

View solution in original post

0 Karma

to4kawa
Ultra Champion
| makeresults count=5000
| streamstats current=f count
| eval ref = "a ref of ".((count % 5) + 1)

Hi, @ChrisCLewis
My machine can't work with count=500000000
but , your machine will work.

0 Karma

ChrisCLewis
Communicator

Many thanks for the answer, never clocked the "current=f" option...

0 Karma

richgalloway
SplunkTrust
SplunkTrust

It's unclear how the 'Ref' column is to be computed. Please explain.

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

aberkow
Builder

+1 to what @richgalloway said. Ideally you can give us a few more example logs and the edge cases you want the code to be able to handle, as well as why streamstats won't work. Thanks!

0 Karma

ChrisCLewis
Communicator

Hi,

Thank you for getting back.

What is in the logs will not determine what the reference number would be.
I am looking at a fixed range of references e.g. 1 through 5 (could also easily be a through e) and the earliest / record would take a reference of one
2nd, a ref of 2
3rd, a ref of 3
4th, a ref of 4
5th, a ref of 5
6th, a ref of 1
7th, a ref of 2
...
10th, a ref of 5
11th, a ref of 1 etc
this would continue through all records until they all have a ref from the 1 through 5 range.

There could easily be 5 million records to go through.

Many thanks

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Your Feedback. Our Roadmap. Visit the PX Feedback Booth at .conf26

You use Splunk every day, come and help shape what's next.  Save Your Seat: Product-Focused Sessions at ...

Agentic SOC Triage: Investigating Splunk ES Notables with MCP Server and a Local LLM

The Problem: Too Many Alerts, Too Little Context Security operations teams running Splunk Enterprise Security ...

Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas

Watch Now Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas     Do you ever feel ...