Splunk Search

What data transform approach should I use with this? MV, tranpose, ...?

ChioNeng
Explorer
Im kinda newbie here in splunk. Whats the difference between multivalue and transpose command? how can i convert this input to this desired output? (see tables below) Is Multivalue or transpose command can manage this?

For a newbie like me those commands is kinda tricky. Many thanks in advance
 

input:

Field1Field2Country1-Jun1-Jul1-Aug1-Sep1-Oct
XABThailand2323433111
YCDSingapore232125222
ZEFPhilippines3156438423

 

output:

Field1Field2CountryMonthValue
XABThailand1-Jun23
XABThailand1-Jul2343
XABThailand1-Aug31
XABThailand1-Sep1
XABThailand1-Oct 1
YCDSingapore1-Jun2
YCDSingapore1-Jul321
YCDSingapore1-Aug2
YCDSingapore1-Sep52
YCDSingapore1-Oct 22
ZEFPhilippines1-Jun31
ZEFPhilippines1-Jul56
ZEFPhilippines1-Aug43
ZEFPhilippines1-Sep84
ZEFPhilippines1-Oct 23
Labels (1)
0 Karma
1 Solution

to4kawa
Ultra Champion
| makeresults 
| eval _raw="Field1	Field2	Country	1_Jun	1_Jul	1_Aug	1_Sep	1_Oct
X	AB	Thailand	23	2343	31	1	1
Y	CD	Singapore	2	321	2	52	22
Z	EF	Philippines	31	56	43	84	23" 
| multikv 
| table Field1 Field2 Country 1_Jun 1_Jul 1_Aug 1_Sep 1_Oct 
| foreach 1_* 
    [ rename <<FIELD>> as 1-<<MATCHSTR>>] 
| rename COMMENT as "this is your sample. from here, the logic"    
| eval tmp=mvzip(Field1,mvzip(Field2,Country)) 
| fields - F* Country 
| untable tmp Month Value 
| rex field=tmp "(?<Field1>[^,]+),(?<Field2>[^,]+),(?<Country>.*)" 
| fields - tmp 
| eval Month=strptime(Month."2019","%d-%b%Y") 
| table Field* Country Month Value 
| fieldformat Month=strftime(Month,"%d-%b") 
| sort Field1 Month

mvexpand or tranpose is not need.

View solution in original post

0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval _raw="Field1	Field2	Country	1_Jun	1_Jul	1_Aug	1_Sep	1_Oct
X	AB	Thailand	23	2343	31	1	1
Y	CD	Singapore	2	321	2	52	22
Z	EF	Philippines	31	56	43	84	23" 
| multikv 
| table Field1 Field2 Country 1_Jun 1_Jul 1_Aug 1_Sep 1_Oct 
| foreach 1_* 
    [ rename <<FIELD>> as 1-<<MATCHSTR>>] 
| rename COMMENT as "this is your sample. from here, the logic"    
| eval tmp=mvzip(Field1,mvzip(Field2,Country)) 
| fields - F* Country 
| untable tmp Month Value 
| rex field=tmp "(?<Field1>[^,]+),(?<Field2>[^,]+),(?<Country>.*)" 
| fields - tmp 
| eval Month=strptime(Month."2019","%d-%b%Y") 
| table Field* Country Month Value 
| fieldformat Month=strftime(Month,"%d-%b") 
| sort Field1 Month

mvexpand or tranpose is not need.

0 Karma

ChioNeng
Explorer

thanks a lot @to4kawa 🙂 

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