Splunk Search

How to search for a pattern in logs using regex or rex

srinivas0704
New Member

I have following lines in logs

1 ADM.ADMX policies
Found ADM/ADMX policies

How do I search to filter only 1 ADM/ADMX policies?

0 Karma

to4kawa
Ultra Champion

you can't do that, because there is not 1 ADM/ADMX policies

| makeresults
| eval _raw="1 ADM.ADMX policies
Found ADM/ADMX policies"
| multikv noheader=t 
| table _raw
| regex "\d*\sADM\.ADMX\spolicies"

We can't answer that because that's not what you're talking about in the question and comment.
Check the results of regex before saying there is no result of stats.

0 Karma

sanjeev543
Communicator

@srinivas0704 Could you try index=foo | regex _raw="1\s+ADM\.ADMX\spolicies" if you need to match with 1 ADM.ADMX policies literally but if you need to capture string with any digit at the start you can try with index=foo | regex _raw="\d\s+ADM\.ADMX\spolicies"

0 Karma

srinivas0704
New Member

@sanjeev543 regex _raw="\d\s+ADM\/ADMX\spolicies"| stats count but still count shows as 0

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Have you tried index=foo "ADM/ADMX" or index=foo | regex "ADM\/ADMX"?

---
If this reply helps you, Karma would be appreciated.
0 Karma

srinivas0704
New Member

Hi I have tried first one,my intention is to take line which starts from digit and has ADM/ADMX

0 Karma

richgalloway
SplunkTrust
SplunkTrust

OK. I misunderstood the question. Try \d\sADM\/ADMX.

---
If this reply helps you, Karma would be appreciated.
0 Karma

srinivas0704
New Member

@richgalloway Not a problem regex _raw="\d\s+ADM\/ADMX\spolicies"| stats count ,but still count shows as 0

0 Karma

richgalloway
SplunkTrust
SplunkTrust

There's a contradiction in what you want to find. Is it "1 ADM.ADMX policies" or "1 ADM/ADMX policies"? My latest response will find the latter. This should find the former: \d\sADM\.ADMX policies.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...