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

Unlocking Unified Insights: New Gigamon Federated Search App for Splunk

In today’s data-heavy environment, organizations are caught in a data distribution dilemma. As data volumes ...

GA: New Data Management App in Splunk Platform

Streamlining Data Management: Introducing a unified experience in Splunk Managing data at scale shouldn’t feel ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...