Splunk Search

Foreach fails if field contains colon or dot.

iet_ashish
Explorer

On running this search,

  | makeresults count=20
    | streamstats count
    | eval "genie.name"="foo", "genie:id"="bar"
    | foreach genie* 
        [eval new_<<MATCHSTR>>=<<FIELD>>+"some string"]

I am expecting that two new fields named new_name and new_id would show, but that doesn't happen. Also an error comes up Failed to parse templatized search for field 'genie:id'

I am running on my local Splunk instance.

Thanks.

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

It's not foreach that's failing, it's eval interpreting the dot as the concatenation operator. Enclose field names with operators in them in single quotes:

| foreach genie* [ eval new_<<MATCHSTR>> = '<<FIELD>>' + "some string" ]

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

It's not foreach that's failing, it's eval interpreting the dot as the concatenation operator. Enclose field names with operators in them in single quotes:

| foreach genie* [ eval new_<<MATCHSTR>> = '<<FIELD>>' + "some string" ]

iet_ashish
Explorer

Thank you so much. This worked.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...