Splunk Search

escaping hyphen if any field has hyphen(-) as value

thambisetty
SplunkTrust
SplunkTrust

Hi
I have data like below in the Active Directory.

Account Name

-
L-15485
D-5486
BLR-DC-09$

Here is my query;
| search "Account Name"="-"

showing Output:

BLR-DC-09$

but actual output to be expected:

L-15485
D-5486
BLR-DC-09$

Note: I read splunk document for -(hyphen) it says - for match any character.
Now my question is how to escape that one as it works.

————————————
If this helps, give a like below.
Tags (1)
0 Karma

linu1988
Champion

Hello,
you need the where clause.

...|where "Account Name" like "%-%-%"

Thanks,
L

0 Karma

ewelch_splunk
Splunk Employee
Splunk Employee

My use case was a little different, I was trying to remove Account_Name = "-" from sourcetype = ActiveDirectory, and the where clause was the only method that I could find that produced the results I needed. Thanks!

0 Karma

aweitzman
Motivator

I'm not sure where you read that hyphen matches any character in Splunk. Could you please provide a link to where it says that? I can't think of a circumstance where it does, especially inside quotes.

I don't think I understand what you mean by "escape." Are you trying to write a search that returns all rows except the ones where the Account Name field has just a hyphen in it? And if so, does:

"Account Name"!="-"

not work? If not, how about:

"Account Name"!="\-"

What does that get you?

0 Karma

thambisetty
SplunkTrust
SplunkTrust

for hyphen?

————————————
If this helps, give a like below.
0 Karma

somesoni2
Revered Legend

Try | search "Account Name"="*"

0 Karma

yannK
Splunk Employee
Splunk Employee

have you tried :

| search "Account Name"="*-*"

0 Karma

thambisetty
SplunkTrust
SplunkTrust

I tried that one by that also im getting only BLR-DC-09$
I want to remove only - values from that field.
your query is wrong..

————————————
If this helps, give a like below.
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 ...