Splunk Search

Import a matrix

youngsuh
Contributor

Q1:  is there a way to import a matrix into Splunk? 

Q2:  What SPL command gives me all values set to true and tells me x, y coordinates?  (object here is to create table)

Here is an example of the matrix that I would like to import.  (Q3:  What would be SPL command provided the field name for the x, y that is true)

 abcdef
1010110
2101001
3010110
4101110
5011011
6101010
Labels (5)
Tags (5)
0 Karma
1 Solution

tscroggins
Influencer

You'll need to give the first column a name, e.g. row:

rowabcdef
1010110
2101001
3010110
4101110
5011011
6101010

 

Next, convert the table to comma separated values:

row,a,b,c,d,e,f
1,0,1,0,1,1,0
2,1,0,1,0,0,1
3,0,1,0,1,1,0
4,1,0,1,1,1,0
5,0,1,1,0,1,1
6,1,0,1,0,1,0

Save the contents to a file, e.g. youngsuh_matrix.csv, and upload the file to Splunk as a lookup from Settings > Lookups. Click + Add New next to Lookup table files.

Finally, run this search:

| inputlookup youngsuh_matrix.csv
| untable row column value
| where value==1

For "x, y" coordinates:

| inputlookup youngsuh_matrix.csv
| untable row column value
| where value==1
| eval coord=row.", ".column
| table coord

coord
1, b
1, d
1, e
2, a
2, c
2, f
3, b
3, d
3, e
4, a
4, c
4, d
4, e
5, b
5, c
5, e
5, f
6, a
6, c
6, e

 

View solution in original post

tscroggins
Influencer

You'll need to give the first column a name, e.g. row:

rowabcdef
1010110
2101001
3010110
4101110
5011011
6101010

 

Next, convert the table to comma separated values:

row,a,b,c,d,e,f
1,0,1,0,1,1,0
2,1,0,1,0,0,1
3,0,1,0,1,1,0
4,1,0,1,1,1,0
5,0,1,1,0,1,1
6,1,0,1,0,1,0

Save the contents to a file, e.g. youngsuh_matrix.csv, and upload the file to Splunk as a lookup from Settings > Lookups. Click + Add New next to Lookup table files.

Finally, run this search:

| inputlookup youngsuh_matrix.csv
| untable row column value
| where value==1

For "x, y" coordinates:

| inputlookup youngsuh_matrix.csv
| untable row column value
| where value==1
| eval coord=row.", ".column
| table coord

coord
1, b
1, d
1, e
2, a
2, c
2, f
3, b
3, d
3, e
4, a
4, c
4, d
4, e
5, b
5, c
5, e
5, f
6, a
6, c
6, e

 

youngsuh
Contributor

 Encountered the following error while trying to save: File has no line endings 

any suggestions?

Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The multikv command will read that table, but it will convert each row into a separate event so the table will no longer be a table.  I'm not aware of any command that will treat the table as an object and there certainly is no command that will return all the 1's in the table.  This could be an opportunity to create an external command.

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Developer Spotlight with Paul Stout

Welcome to our very first developer spotlight release series where we'll feature some awesome Splunk ...

State of Splunk Careers 2024: Maximizing Career Outcomes and the Continued Value of ...

For the past four years, Splunk has partnered with Enterprise Strategy Group to conduct a survey that gauges ...

Data-Driven Success: Splunk & Financial Services

Splunk streamlines the process of extracting insights from large volumes of data. In this fast-paced world, ...