Splunk Search

Can anyone tell me why Splunk is throwing this error when using the foreach command?

nkankur
Path Finder
| foreach V* [eval PAC<<MATCHSTR>>=<<FIELD>>-Voice], 
| foreach PAC* [eval <<FIELD>>=if(<<FIELD>> < 0, -<<FIELD>>, 0)]

error -> Error in 'foreach' command: Only the last argument should be a search pipeline

0 Karma

koshyk
Super Champion

I can find 3 issues in above query.

  1. there is a comma , in your first line end. That's is wrong
  2. the string -voice should be concatenated to field using . " (dot and double quotes) to make it a string.
  3. the PAC value is doing if based on a numeric value, but you have concatenated with a string. This might give unexpected results

Please find corrected query

|makeresults | eval total=0| eval VariableA="100"| eval VariableB="200"
| foreach V* [eval PAC_<<MATCHSTR>>=<<FIELD>> . "-voice" ]  
| foreach PAC* [eval <<FIELD>>=if(<<FIELD>> < 0, -<<FIELD>>, 0)]
0 Karma

horsefez
Motivator

Hi nkankur,
I see an odd "," at the end of the first foreach statement... sure this needs to be there?

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

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 ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...