Splunk Search

Is there a way to trim URL string from a table?

jrevolorio
Explorer

So, I want to create a table where it shows the time, source IP, and URL.

sourcetype=* src_ip=* url=* | table _time, src_ip, url

The search runs fine however the URL comes back with a long string.

Example= https://www.google.com/xxx_xxx?atyp=csi&ei=tWelWaipKMOJmQGb_Lr4Cg&s=newtab&action=update&ima=1&ime=0...

Is there a way to trim the string from the URL to only show up to google.com/xxx_xxx?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try like this

sourcetype=* src_ip=* url=* | table _time, src_ip, url | eval url=mvindex(split(url,"?"),0)

OR

sourcetype=* src_ip=* url=* | table _time, src_ip, url | rex field=url "^(?<url>[^\?]+)"

View solution in original post

niketn
Legend

You can also try replace() function with regular expression pattern

sourcetype=* src_ip=* url=* 
| table _time, src_ip, url 
| eval url=replace(url,"(^[^\?]+)(\?.*)","\1")
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

sourcetype=* src_ip=* url=* | table _time, src_ip, url | eval url=mvindex(split(url,"?"),0)

OR

sourcetype=* src_ip=* url=* | table _time, src_ip, url | rex field=url "^(?<url>[^\?]+)"

jrevolorio
Explorer

Thanks! Worked like a charm

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...