Splunk Search

Compare Lines in a Single Field

airalee
New Member

Hello All,

Is there a way in a Splunk search to iterate through a multiline field and do stats on each value/each line? The goal is to display only when Field2 has varying lengths of values. So in this case, the result will only display the rows Apples and Bananas.

Example Table:
Field1, Field2 (where \n is an actual newline and not the characters for a newline)
Apples, 12345 \n 123456 \n 1234
Bananas, 123 \n 12345
Oranges, 123456 \n 123456 \n 123456

Thanks!

Tags (1)
0 Karma
1 Solution

to4kawa
Ultra Champion
|makeresults
|eval _raw="Field1, Field2
Apples, 12345 123456 1234
Bananas, 123 12345
Oranges, 123456 123456 123456"
|multikv forceheader=1
|table Field1, Field2
|eval Field2=split(trim(Field2)," ")
|rename COMMENT as "this is sample. from here, the logic"
|eval vary1=mvcount(Field2), vary2=mvcount(mvdedup(Field2))
| where vary1==vary2

View solution in original post

0 Karma

to4kawa
Ultra Champion
|makeresults
|eval _raw="Field1, Field2
Apples, 12345 123456 1234
Bananas, 123 12345
Oranges, 123456 123456 123456"
|multikv forceheader=1
|table Field1, Field2
|eval Field2=split(trim(Field2)," ")
|rename COMMENT as "this is sample. from here, the logic"
|eval vary1=mvcount(Field2), vary2=mvcount(mvdedup(Field2))
| where vary1==vary2
0 Karma

airalee
New Member

Thanks @to4kawa ! This is what I was looking for. I did not realize you can use the mvdedup inside the mvcount, thanks again!

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@airalee

Can you please share your expected output from your shared data?

Meanwhile, you can try below search for getting exact multivalue field.

YOUR_SEARCH
| eval Field2=replace(Field2,"\n",",") 
| makemv delim="," Field2

Sample search for extraction:

| makeresults 
| eval Field1="Apples", Field2="12345
123456
1234" 
| append [| makeresults 
| eval Field1="Bananas", Field2="123
12345" ]
| append [| makeresults 
| eval Field1="Oranges", Field2="123456
123456
123456" ]
| eval Field2=replace(Field2,"\n",",") 
| makemv delim="," Field2
0 Karma

airalee
New Member

Hi @kamlesh_vaghela , thanks for your help! I got the results from @to4kawa below

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...