Splunk Search

Map column from another table to my currently used table

Jimenez
Explorer

Hi all,

I have the following issue. I have a table A 

col1col2
Aaa
Bbb
Caa

 

And a table B

colAcolB
aaFYI
bbLOL

 

I need to add to table A the column colB based on the matching values from col1 (table A) and colA (table B) and it should look like:

col1colBcol2
AFYIaa
BLOLbb
CFYIaa

 

so basically map the values from col2 to colA and add colB based on the matches

Thanks for your support,

Labels (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

As with any good languages, there are many ways to do this.  A simple and semantically expressive method is to use coalesce.

sourcetype IN (tableA, tableB)
| eval col2 = coalesce(col2, colA)
| stats values(col1) as col1 values(colB) as colB by col2

 

Tags (1)

PickleRick
SplunkTrust
SplunkTrust

Right. Didn't notice the columns were not named the same in both sourcetypes.

0 Karma

Jimenez
Explorer

They are actually results coming from different event types. Each event contains different fields.

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Yes. But are those results of some searches that you want to "merge" or do you simply have two different sourcetypes from which different sets of fields are extracted?

If it's the latter, your solution should be relatively simple

<some restriction on index(es)> sourcetype IN (sourcetype1, sourcetype2)
| stats values(colA) as colA values(colB) as colB values(col1) as col1 values(col2) as col2 [...] by common_column

If you want all columns, you might simply go with

values(*) as *
0 Karma

isoutamo
SplunkTrust
SplunkTrust
Are those tables individual sourcetypes on index or results of your SPL queries? If last, can you share it so we can modify it to create your requested result?
0 Karma

PickleRick
SplunkTrust
SplunkTrust

What do you mean by "table"? There are several different possible approaches depending on where those "tables" come from.

0 Karma
Get Updates on the Splunk Community!

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

 Prepare to elevate your security operations with the powerful upgrade to Splunk Enterprise Security 8.x! This ...

Get Early Access to AI Playbook Authoring: Apply for the Alpha Private Preview ...

Passionate about security automation? Apply now to our AI Playbook Authoring Alpha private preview ...

Reduce and Transform Your Firewall Data with Splunk Data Management

Managing high-volume firewall data has always been a challenge. Noisy events and verbose traffic logs often ...