Splunk Search

Copy a row in a table

komalg
New Member

Hi, I am trying to conditionally add records to my table with a slight modification to the data. for example
Date ID Type Duration
2019-11-22 ABC XYZ 4
2019-11-26 BCD YZX 2

So for this record I am trying to add data to my table like
Date ID Type Duration
2019-11-22 ABC XYZ 4
2019-11-23 ABC XYZ 3 -- Add new row
2019-11-24 ABC XYZ 2 -- Add new row
2019-11-25 ABC XYZ 1 -- Add new row
2019-11-26 BCD YZX 2 -- Add new row
2019-11-27 BCD YZX 1 -- Add new row

Any pointers on this?

Thanks.

Tags (1)
0 Karma

to4kawa
Ultra Champion
| makeresults
| eval _raw="Date,ID,Type,Duration
2019-11-22,ABC,XYZ,4
2019-11-26,BCD,YZX,2"
| multikv
| table Date,ID,Type,Duration
| rename COMMENT as "this is the sample you provide"
| rename COMMENT as "From here, the logic"
| eval Date=strptime(Date,"%F")
| eval Date_after = relative_time(Date,"+".(Duration - 1)."d")
| eval Date=mvappend(Date,Date_after)
| mvexpand Date
| rename Date as _time
| timechart span=1d values(*) as *
| rename _time as Date
| table Date,ID,Type,Duration
| filldown ID, Type
| reverse
| streamstats count as Duration by ID
| reverse
| fieldformat Date=strftime(Date,"%F")

Hi, @komalg
How about this?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Where does this new data come from?

---
If this reply helps you, Karma would be appreciated.
0 Karma

mydog8it
Builder

A Splunk Table is a visualization of data returned by a search, they do not persist beyond the "viewable" use of the original search. If the table is to be refreshed with new data, a new search is used to pull fresh results for the visualization.

Perhaps you mean a lookuptable, which looks and feels like a spreadsheet and it persists beyond the presentation of the search results.

Here is the SPL for a table result if all the fields in the example are already extracted:

        index=your_index sourcetype=your_sourcetype Date=* ID=* Type=* Duration=* | table Date ID Type Duration

Here is the SPL to create or append results in a lookuptable (make sure the lookuptable name ends in .csv):

   index=your_index sourcetype=your_sourcetype Date=* ID=* Type=* Duration=* 
    | outputlookup append=true your_lookup_name.csv

If you want to view the lookuptable after it has been populated, here is the SPL:

|inputlookup your_lookup_name.csv
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Event Series: Telemetry Pipeline Management

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...

Deep insights, no barriers: Splunk Observability Cloud Free Edition

As software delivery cycles continue to accelerate, observability shouldn’t be a luxury — it should be a ...