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!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...