Splunk Search

How to extract a text from a field

nirmalya2006
Path Finder

Hi All

I have a field which has urls in this pattern

GET /echo/index?page=content&id=PRO19579&viewlocale=es_ES HTTP/1.1  
GET /echo/index?page=relatedLinks&id=PRD1296&viewLocale=null&channel=REFERENCE&_=1454507716347 HTTP/1.1

I have to extract only the part between 'page' and '&' ie 'content' and 'relatedLinks' from it.
I tried to extract it using substr and rtrim but I am unable to trim contents after &.
My search string is

| eval URL = substr(field7,17) | eval URL = rtrim(URL,"^\\&.*") 

After using substr my result is

page=content&id=PRO19579&viewlocale=es_ES HTTP/1.1
page=relatedLinks&id=PRD1296&viewLocale=null&channel=REFERENCE&_=1454507716347 HTTP/1.1

But the rtrim function is not at all working to remove the text with and after &.

Please help.

0 Karma
1 Solution

sundareshr
Legend

Use rex instead

... | rex "page=(?<page>[^&]+)" | table page

View solution in original post

sundareshr
Legend

Use rex instead

... | rex "page=(?<page>[^&]+)" | table page
Get Updates on the Splunk Community!

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...