Splunk Search

How to Parse response string value?

pmjoen
Explorer

I have a log I am am trying to parse one of the responses

Field Value

Test Response

Response Test

Testing_Response

For the value "Testing_Response" I would like it to display "Testing" in the results.

Labels (2)
0 Karma
1 Solution

pmjoen
Explorer

Resolved with following:

replace “Document C_*” with “Document C” in <field name>

View solution in original post

0 Karma

pmjoen
Explorer

Resolved with following:

replace “Document C_*” with “Document C” in <field name>

0 Karma

bowesmana
SplunkTrust
SplunkTrust

You can rename fields like this

| rename Testing_Response as Testing

 or if you are talking about changing the value of a field then there are various ways, but try this

| eval your_field=if(your_field="Testing_Response", "Testing", your_field)

 

pmjoen
Explorer

In this scenario, the data is similar to this:

Document A

Document B

Document C_1425

Document C_2235

Document C_5134

I am grouping them together but due to the _number changing not matching it wont group them and I am looking to remove the _number from each one.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Here are two ways, using regex to do that

| makeresults
| eval Data=split("Document A,Document B,Document C_1425,Document C_2235,Document C_5134", ",")
| fields - _time
| mvexpand Data
| eval Data_Method_1=replace(Data, "_\d+$", "")
| eval Data_Method_2=Data
| rex field=Data_Method_2 mode=sed "s/_\d+$//"

so, you can either use replace() or rex mode=sed

Either way, you are defining the regex to remove what you don't want

 

 

0 Karma

pmjoen
Explorer

As the value Document C_2235 would grow exponentially, would your example require me to enter all values?

0 Karma

bowesmana
SplunkTrust
SplunkTrust

I think you misunderstood the post - the search I gave was an example showing you how it works using your data. However, the solution is just the replace or rex statement - this regex is simply using a regular expression to remove the bits you don't want - i.e. _ followed by one or more numbers to the end of the string.

| eval Data_Method_1=replace(Data, "_\d+$", "")

Change 'Data' to your field name

 

0 Karma
Get Updates on the Splunk Community!

Cultivate Your Career Growth with Fresh Splunk Training

Growth doesn’t just happen—it’s nurtured. Like tending a garden, developing your Splunk skills takes the right ...

Introducing a Smarter Way to Discover Apps on Splunkbase

We’re excited to announce the launch of a foundational enhancement to Splunkbase: App Tiering.  Because we’ve ...

How to Send Splunk Observability Alerts to Webex teams in Minutes

As a Developer Evangelist at Splunk, my team and I are constantly tinkering with technology to explore its ...