Splunk Search

Why doesn't rex sed work with this expression: s/=[^&]*//g

danapsimer
New Member

I have used rex to extract a URL from log message. I then want to eliminate the parameter values so I can build statistics based on the URL. To do this I use the following rex command:

rex field=request_url mode=sed "s/=[^&]*//g"

With the following input:

/UsomCustomer/customers?storeNumber=####&phone=##########

I get:

/UsomCustomer/customers?storeNumber

but I expect

/UsomCusteomr/customers?storeNumber&phone

When I execute sed locally with the same expression and the same input it works.

$  sed 's/=[^&]*//g' < test-sed.txt
/UsomCustomer/customers?storeNumber&phone 

One curious thing is that when I take away the second rex command and look at the "request_url" field in the UI. I see '\u0026' instead of & in the display.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi danapsimer,
try something like

| rex field=request_url "^(?<url>[^\?]*)"

Bye.
Giuseppe

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

When I run the following, it get what you are expecting:

| makeresults 
| eval url="/UsomCustomer/customers?storeNumber=####&phone=##########"
| rex field=url mode=sed "s/=[^&]*//g"

which is:

/UsomCustomer/customers?storeNumber&phone

It does look like you have a character issue in the search string.

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...