Splunk Search

How to exclude last 2 parts of the URL in Splunk?

bharath999
Observer

I have a URL as below

1.aa/bb/cc/dd

2.nbcn/hbd/hvhd/hbxn

 

Need to regular expression to get the below output

1.aa/bb

2.nbcn/hbd

Labels (2)
Tags (1)
0 Karma

somesoni2
Revered Legend

If you always want to exclude last 2 parts (regardless of how many segment your URL may have), try something like this

(?<shorturl>.+)\/[^\/]+\/[^\/]+$

 

In-line search

your search | rex "(?<shorturl>.+)\/[^\/]+\/[^\/]+$"

 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

An alternative is to use mode=sed on the original URL field

| rex mod=sed field=url "s/(\/[^\/]+){2}$/"

 

 

 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex field=url "^(?<shorturl>[^\/]+\/[^\/]+)"
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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