Splunk Search

How to count the number of times a special character is used in a string or field

georgemak
Engager

 I have a field called "command" with the below input:

C:\windows\systems32\cmd.exe /c ""c:\program Files(x86)\Microsoft.

So I want to extract all the special characters and need to get the count of number of times a special character is used.. 

For example; I want my result to be like this :

Special character    Count

\                                       5

/                                       1

""                                      1

(                                         1

)                                          1

 

How can I get this done?

 

 

 

 

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex max_match=0 "(?<special>[\"\\\/\(\)])"
| stats count by special

The issue with this is that you appear to be wanting to count "" as one character - if this is what you actually intend, then you should either divide the result for this character (pair) by 2 or substitute "" for " in the original string

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex max_match=0 "(?<special>[\"\\\/\(\)])"
| stats count by special

The issue with this is that you appear to be wanting to count "" as one character - if this is what you actually intend, then you should either divide the result for this character (pair) by 2 or substitute "" for " in the original string

0 Karma

georgemak
Engager

Thank you! 

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...