Splunk Search

Excluding either the start or end of a transaction when parsing result with rex command

jbrenner
Path Finder

I'm using the rex command to parse a value out of the results of a transaction command. Is there an easy way to restrict the resulting capture from searching either the start or end block of the transaction? This would be much easier than doing it in the regex itself, since both blocks of text returned are very similar.

Thanks! Jonathan

Labels (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

There is a potentially rather expensive way to do it.  Suppose your raw events are all single lines, you can do something like

 

| eval beginning_of_transaction = mvindex(split(_raw, "
"), 0) ``` use index -1 for end of transaction ```
| rex field=beginning_of_transaction "<your regex>"

 

If the events are not all single line, but there is a distinct string (including newline) to split them without interfering with your regex, this formula can still work.

Update: Your title says to exclude.  If exclusion is the goal, I assume that you meant to exclude start AND end, not start or end.  This can be achieved with

| eval middle_of_transaction = mvindex(split(_raw, "
"), 1, -2)
| rex field=middle_of_transaction "<your regex>"

 

Tags (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The rex command looks at every result.  If you need to exclude certain results then you'll have to craft a regular expression that does so.  Another option is to filter the start and end blocks out of the results - assuming they're not needed for other parts of the query.

---
If this reply helps you, Karma would be appreciated.
0 Karma
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 ...