Splunk Search

Convert multi-value expression to field names and values

rharrisssi
Path Finder

I have a string,

"one:isone,two:istwo,three:isthree"

The goal is to convert these to fields and values, without knowing what will be in the string. Basically the following, but automagic.

| eval one="isone"
| eval two="istwo"
...
0 Karma

micahkemp
Champion

Splunk enables this type of behavior with the _KEY_1 and _VAL_1 syntax:

in transforms.conf:

[colon_comma_separated]
REGEX = (?<_KEY_1>[^:]+):(?<_VAL_1>[^,]+)

in props.conf:

[<sourcetype>]
REPORT-colon_comma_separated

From the transforms.conf doc:

  * If the REGEX extracts both the field name and its corresponding field
    value, you can use the following special capturing groups if you want to
    skip specifying the mapping in FORMAT:
      _KEY_<string>, _VAL_<string>.
  * For example, the following are equivalent:
    * Using FORMAT:
      * REGEX  = ([a-z]+)=([a-z]+)
      * FORMAT = $1::$2
    * Without using FORMAT
      * REGEX  = (?<_KEY_1>[a-z]+)=(?<_VAL_1>[a-z]+)
    * When using either of the above formats, in a search-time extraction,
      the regex will continue to match against the source text, extracting
      as many fields as can be identified in the source text.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Guided Onboarding with Auto-schema Is Now Generally Available

  We are excited to announce the General Availability of Guided Onboarding with Auto-Schematization ...

ATTENTION: We’re Moving! (AGAIN!)

The Splunk Community Slack is undergoing a system migration to keep our workspace secure and ...

Deep Dive: Optimizing Telemetry Pipelines in Splunk Observability Cloud

In this session, we will peel back the layers of Splunk Observability Cloud’s cost-optimization features. ...