Splunk Search

Add a for loop on eval command for number of hosts

ssaenger
Communicator

Hi,

i have a query that returns two lines of results based on two hosts.
i then get a result from another query that only returns one line.
When i do the eval command i get a correct 'Match' for the first line but no entry for the second.

How do i apply the 'appendcol' result to both lines?

index =systems sourcetype = stream_stack PID=0x0055 
|  eval Packets=packets*208 
 | stats  latest(Packets) AS Packets by host 
|  appendcols 
    [ search index=systems sourcetype=soms_file_size process=soms  | stats  latest(file_size) AS file_size latest(file_name) AS file_name by process ]
     | eval match=if(Packets=file_size,"OK","Error")
     | table process match Packets file_size file_name host

RESULT

process  match            file_size file_name                                                   host
soms       OK                     27666832  DR_270919_P_5068_719_750_750.out                             chietrp01
           Error                                                                               chietrp02

thanks,

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

That's the way appendcols works. The results from search 2 are added to the results from search 1 on a one-to-one basis. If there are fewer results in search 2 then some results from search 1 will not have the added columns. Also, note that the order in which the results are returned from each search should be the same so the one-to-one pairing of results makes sense.

If you need the results from search 2 to be replicated to all results of search 1 then perhaps filldown will do.

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

View solution in original post

0 Karma

ssaenger
Communicator

Thank you richgalloway this worked.

For those seeking solution, here is the code for filldown, nice and easy -

 index =systems sourcetype = stream_stack PID=0x0055 
 |  eval Packets=packets*208 
  | stats  latest(Packets) AS Packets by host 
 |  appendcols 
     [ search index=systems sourcetype=soms_file_size process=soms  | stats  latest(file_size) AS file_size latest(file_name) AS file_name by process ]
      | filldown process, file_size, file_name
      | eval match=if(Packets=file_size,"OK","Error")
      | table process match Packets file_size file_name host
0 Karma

richgalloway
SplunkTrust
SplunkTrust

That's the way appendcols works. The results from search 2 are added to the results from search 1 on a one-to-one basis. If there are fewer results in search 2 then some results from search 1 will not have the added columns. Also, note that the order in which the results are returned from each search should be the same so the one-to-one pairing of results makes sense.

If you need the results from search 2 to be replicated to all results of search 1 then perhaps filldown will do.

---
If this reply helps you, Karma would be appreciated.
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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...