Splunk Search

How to merge two fields into one field?

lpolo
Motivator

I have the following result set coming from a search:

field_1 field_2
 1       2
 3       4
 5       6

I need to merge these two fields into a new field "output":

output
 1
 2
 3
 4
 5
 6

Thanks,
Lp

Labels (1)
Tags (2)

lguinn2
Legend

If field1 is multivalued, you can do this:

 eval output = mvappend(field1,field2)

To remove nulls:

eval output = mvfilter(output!=null())

ryhluc01
Communicator

@lguinn2 Make this a comment so that it can be accepted as an answer. I found this to be correct.

0 Karma

lpolo
Motivator

Nice learning experience. Thanks.

0 Karma

ibekacyril
Explorer

Sorry for the late show, but this returns null in the second field

0 Karma

seanclark
Engager

I am getting the null response as well.

0 Karma

somesoni2
Revered Legend

Is one of your fields that you're merging contains null values?

0 Karma

seanclark
Engager

Apparently they did, but I could not find where they were. I also had to manipulate this solution some to get what I wanted. I had to fields that had IPs in them so I did this.

myprecious | fillnull value="" source_address ip_address| eval output =ip_address.source_address

0 Karma

lguinn2
Legend

Here is one way- but there is probably something better

yoursearchhere |
rename field1 as output |
append [search yoursearchhere earliest=-24h |
rename field2 as output ]

This runs the search twice...

Notice that I included earliest=-24h for the inner search. Otherwise, this will search over all time - it is not affected by the time selector. [No longer true - the inner search runs over the range specified by the timerange selector.]

landen99
Motivator

The subsearch naturally carries the time of the outer search unless otherwise specified, as I understand it.

lguinn2
Legend

Agreed @landen99, but that was not true in 2012 🙂

0 Karma

Ayn
Legend

Well give more details. You didn't state that this was going to be used across millions events. Also you need to give more details on the search you're using to generate these fields. Do field1 and field2 belong to the same search result? Do both fields always occur in all events you want to apply this to?

lpolo
Motivator

This approach is expensive and might not work when dealing with millions of events.
Thanks.

0 Karma
Get Updates on the Splunk Community!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...