Splunk Search

Search for multiple apperances of a pattern in a field

KMoryson
Explorer

Hi, is there a way to search for more than one appearance of a pattern in a string?

For example:
Command
cmd.exe c:\windows\\\\\\\\sytem32\[...]
cmd.exe c:\windows\sytem32\[...]

I would want to search for rows with more than single consecutive "\" , in case of above only first row to be returned.

Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Have you even tried it?

Due to the way splunk escapes backslash in regex expressions, you need 4 backslashes to match a single backslash in the field, therefore 8 backslashes (as I have used), will find anything more than 1 in the field.

| makeresults
| eval _raw="cmd.exe c:\\windows\\\\\\\\\\\\\\\\sytem32\\[...]
cmd.exe c:\\\\windows\\\\sytem32\\\\[...]
cmd.exe c:\\windows\\sytem32\\[...]"
| multikv noheader=t
| regex _raw="\\\\\\\\"

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| regex _raw="\\\\\\\\"

KMoryson
Explorer

This only matches to this specific amount of backslashes, I want to match for any number above one

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Have you even tried it?

Due to the way splunk escapes backslash in regex expressions, you need 4 backslashes to match a single backslash in the field, therefore 8 backslashes (as I have used), will find anything more than 1 in the field.

| makeresults
| eval _raw="cmd.exe c:\\windows\\\\\\\\\\\\\\\\sytem32\\[...]
cmd.exe c:\\\\windows\\\\sytem32\\\\[...]
cmd.exe c:\\windows\\sytem32\\[...]"
| multikv noheader=t
| regex _raw="\\\\\\\\"

KMoryson
Explorer

So sorry, you are right, this works wonderfully, thank you for help

0 Karma
Get Updates on the Splunk Community!

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...

Everything Community at .conf24!

You may have seen mention of the .conf Community Zone 'round these parts and found yourself wondering what ...

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...