I have a transaction in which field mydata contains repeating values like ("xyz","ijk","ijk","abc","abc","abc","abc","abc","lmn","def","def"). I want to compact this list by representing repeating elements only once, but preserving the order in which each repetition occurs. In effect, this is the output of transaction mvlist=true . (Default transaction implies mvlist=false . The output is a compact, but unordered list.) Is there a list command to do this? The end goal is to illustrate a chain of events like "xyz=>ijk..=>abc..=>lmn=>def.." The closest discussion was http://answers.splunk.com/answers/95363/perform-transaction-for-only-repeating-values-of-field. But the answer there was partial, and does not apply to my use case.
(Updated) Sample data are like:
16-May-2014 00:50:10.386 type=9,mydata=2.10.8
16-May-2014 00:55:23.205 type=9,mydata=2.10.8
16-May-2014 00:59:39.760 type=9,mydata=2.10.8
16-May-2014 01:12:26.410 type=9,mydata=2.10.8
16-May-2014 01:19:55.528 type=9,mydata=2.10.8
16-May-2014 01:41:33.508 type=9,mydata=2.10.8
16-May-2014 01:43:54.872 type=9,mydata=2.10.8
16-May-2014 11:53:43.119 type=9,mydata=2.14.1
16-May-2014 11:53:44.121 type=15,mydata=2.10.8
16-May-2014 11:55:46.376 type=15,mydata=3.2.2
16-May-2014 11:57:09.548 type=15,mydata=3.2.2
16-May-2014 11:58:03.658 type=15,mydata=3.2.2
16-May-2014 11:59:03.782 type=15,mydata=3.2.2
16-May-2014 11:59:06.788 type=15,mydata=3.2.2
16-May-2014 11:59:45.870 type=15,mydata=3.2.2
16-May-2014 12:00:07.914 type=15,mydata=3.2.2
16-May-2014 12:01:25.073 type=15,mydata=2.10.8
16-May-2014 17:01:07.343 type=9,mydata=3.4.6001
16-May-2014 17:19:41.923 type=9,mydata=3.4.6001
16-May-2014 17:20:58.090 type=15,mydata=2.10.8
16-May-2014 17:21:32.159 type=15,mydata=2.10.8
16-May-2014 17:21:51.198 type=15,mydata=2.10.8
16-May-2014 19:48:41.102 type=9,mydata=3.4.6001
16-May-2014 19:49:15.172 type=9,mydata=3.4.6001
16-May-2014 20:35:44.316 type=9,mydata=3.4.6001
16-May-2014 21:15:31.373 type=9,mydata=3.4.6001
With help from Perl community, I came up with the following string method. Though usable, I feel it is lame to use string to compact a list, given that Splunk is list oriented.
source=mydata
| transaction type mvlist=true
| eval flatten=mvjoin(mydata,"=>")
| eval compact=replace(flatten,"([^=]+)(?:=>\1)+","\1..")
| stats max(eventcount) as count by compact type
compact type count
2.10.8..=>2.14.1=>3.4.6001.. 9 14
2.10.8=>3.2.2..=>2.10.8.. 15 12
(Update: max(eventcount) gives the correct count, not sum(eventcount).) Actual chain of events can easily be tested in shell:
$ for t in type=9, type=15,; do fgrep $t < mydata |cut -d\ -f3-|uniq -c; done
7 type=9,mydata=2.10.8
1 type=9,mydata=2.14.1
6 type=9,mydata=3.4.6001
1 type=15,mydata=2.10.8
7 type=15,mydata=3.2.2
4 type=15,mydata=2.10.8
Note: The original example used mvappend to simulate output from transaction, as listed below. ( source=* can be a search that returns at least one event.) But this simulation apparently lacks some important aspect of a transaction.
source=*
| eval mydata=mvappend("xyz","ijk","ijk","abc","abc","abc","abc","abc","lmn","def","def")
| eval flatten=mvjoin(mydata,"=>")
| eval compact=replace(flatten,"([^=]+)(?:=>\1)+","\1..")
| stats values(mydata) by compact flatten
compact flatten values(mydata)
xyz=>ijk..=>abc..=>lmn=>def.. xyz=>ijk=>ijk=>abc=>abc=>abc=>abc=>abc=>lmn=>def=>def abc
def
ijk
lmn
xyz
... View more