Splunk Search

Regarding eval operations on the fields having special characters

sudhir_norway
Engager

I wanted to add this chaining command with my search and display total of the values under fields(columns) "a-b-1"  and "a-b-2" and give the total results as total_requests 

eval total_requests=a-b-1+a-b-2

where "a-b-1" and "a-b-2" is the field1 and field2 which i want to add using '+' operator

I have tried putting fields in double quotes and single quotes but unfortunately  it is not working.

I can do it by renaming the fields but can someone suggest someway to do without renaming it.

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Here is a runanywhere example showing the syntax working.

| makeresults
| eval _raw="
Time	a-b-1	a-b-2	Total_requests
0:00	2	3	5
0:10	4	6	10
0:20	8	10	18"
| multikv forceheader=1
| rename a_b_1 as "a-b-1" a_b_2 as "a-b-2"
| fields Time "a-b-1" "a-b-2"
| fields - _raw _time
``` the lines above set up example data as posted ```
| eval Total_requests='a-b-1'+'a-b-2'

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Is this what you mean?

| eval total_requests='a-b-1'+'a-b-2'
0 Karma

sudhir_norway
Engager

Yes but its not working as expected

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Can you give an example of when it is not giving the expected result? Also, is this happening for every event or just some of them?

0 Karma

sudhir_norway
Engager

| timechart span=10m count by host |rename a-b-1 as a1 |rename a-b-2 as a2 |eval total_requests=a1+a2

Above works as expected and chart displays with total_requests correctly

But when i tried 

| timechart span=5m count by host |eval total_requests=a-b-1+a-b-2 then it dont work(I tried keeping both in single quotes and double quotes but didnt worked).Its not displaying the total

Below is the sample data and what i am looking for

Timea-b-1a-b-2Total_requests
0:00235
0:104610
0:2081018

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Here is a runanywhere example showing the syntax working.

| makeresults
| eval _raw="
Time	a-b-1	a-b-2	Total_requests
0:00	2	3	5
0:10	4	6	10
0:20	8	10	18"
| multikv forceheader=1
| rename a_b_1 as "a-b-1" a_b_2 as "a-b-2"
| fields Time "a-b-1" "a-b-2"
| fields - _raw _time
``` the lines above set up example data as posted ```
| eval Total_requests='a-b-1'+'a-b-2'
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...