Splunk Search

Splunk Search and Iterate over a log

vinorama
Explorer

Can I do the following in Splunk:

Search for a line using a query.

Iterate from that line onwards in the log.

search source=log.txt "search value"

log.txt
Line 1
Line 2
Line 3 "search value"
Line 4
Line 5

I would like my search to return Line 3.

I would then like to iterate the log in this order Line 3->Line 4->Line 5.

Is this allowed in Splunk and how do I do this?

Tags (3)

somesoni2
Revered Legend

Try following. This will gives all the events which has same or greater value of _time value as compared to the event containing "search value". "|head1" ensures that single value is returned from subsearch.

source=log.txt  |eval joinfield=1 | join type=outer joinfield [search  source=log.txt  "search value" | head 1 | eval joinfield=1 | eval ss_time= _time | table joinfield, ss_time]  | where _time >= ss_time | fields - joinfield,ss_time
0 Karma

Ayn
Legend

You could do this using the transaction command. http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction

... | transaction startswith="search value" maxevents=3 | search "search value"
0 Karma

vinorama
Explorer

I am trying to hit an try point in the log where there is an occurence of an event.

The sequential log messages after that line tell me more about the event.

Line 4 and Line 5 will have further details on the event that is represented in Line 3.

This is the purpose of iteration.

0 Karma

Ayn
Legend

What would the purpose and results be of the iteration? What happens when you encounter Line 4 and Line 5 respectively?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...