Splunk Search

What rex to use for the extraction of virtual from URI?

lbonnes
Observer

These two cells are examples of results I see in IIs logs. 

If the field is just a / (backslash) ( as in the first example data cell ) I want to return just the /. 

If there are characters after the first / (like search in #2) , I need to return the text between the backslashes.  

/
/search/20191108/master.svc

 

My results would look like this. 

field1

root   

search

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This should do it.

| rex "\/(?<field1>[^\/]+)"
| eval field1=if(isnull(field1) OR field1="","root", field1)

  The rex command grabs everything between the first two slashes.  The eval command presumes a missing or empty field1 means the root was specified. 

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

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...