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.
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...