Splunk Search

Return position of value within a multivalue field?

pattyshychen
Engager

Is there a command to return the position of a value within a multivalue field? I have already parsed out the multivalue field into individual rows, but want to add an associated identifier for each that tells me the position.

For example --

Original multivalue field: (A,B,C,D,E,F,G,H,I,J,K,L,....)

Ultimately I would like the MV field displayed as:

[value][position]

A 1

B 2

C 3

D 4

E 5

....

Any ideas? Any help would be appreciated!

Tags (2)

gschr
Path Finder

You can use streamstats in combination with mvexpand to achieve that.

The section up to here is used to produce your kind of data (and to add an unique identifier):

* | head 2 | streamstats count AS ID | eval value=if(ID=1,"A,B,C,D,E,F","G,H,I,J") | makemv delim="," value | table ID value

Now to return the position you use the following code:

* | head 2 | streamstats count AS ID | eval value=if(ID=1,"A,B,C,D,E,F","G,H,I,J") | makemv delim="," value | table ID value | mvexpand value | streamstats count AS position by ID  | table value position
0 Karma

pattyshychen
Engager

Good questions.

Yes - the number of values in the mv field does change depending on the row.

Parsing done by:
source=...|makemv delim="," mvfieldname | mvexpand mvfieldname

0 Karma

lukejadamec
Super Champion

Does the number of fields in the mv field change?
How did you "parse" out the fields?

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...