- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

mockingj
New Member
03-19-2020
04:12 AM
Hello Splunkers,
I have a trouble with the result, example i have some data log
Goat | alive
Goat | dead
Goat | alive
Rabit | alive
Rabit | dead
my trouble is , how to get data count alive or dead , example a Goat (alive =2 , dead = 1) diff = alive - dead (1) , and Rabit(alive=1 , dead=1) diff = alive - dead (0), i want to create table of result
Animal | alive | dead | diff
Goat | 2 | 1 | 1
Rabit | 1 | 1 | 0
please help me for the query, thank you splunkers
1 Solution
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

richgalloway

SplunkTrust
03-19-2020
05:50 AM
See if this helps.
... | stats count(eval(state="alive")) as AliveCount, count(eval(state="dead")) as DeadCount by Animal
| eval diff = AliveCount - DeadCount
| table Animal, AliveCount, DeadCount, diff
---
If this reply helps you, Karma would be appreciated.
If this reply helps you, Karma would be appreciated.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

richgalloway

SplunkTrust
03-19-2020
05:50 AM
See if this helps.
... | stats count(eval(state="alive")) as AliveCount, count(eval(state="dead")) as DeadCount by Animal
| eval diff = AliveCount - DeadCount
| table Animal, AliveCount, DeadCount, diff
---
If this reply helps you, Karma would be appreciated.
If this reply helps you, Karma would be appreciated.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

mockingj
New Member
03-19-2020
07:08 AM
wonderful answer :)) , the best word by Animal , thank you very much
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

manjunathmeti
Champion
03-19-2020
05:50 AM
hi @mockingj,
Try this:
| makeresults
| eval _raw="_raw
Goat | alive
Goat | dead
Goat | alive
Rabit | alive
Rabit | dead"
| multikv forceheader=1
| rex "(?<Animal>\w+)\s\|\s(?<status>\w+)"
| stats count(eval(status="alive")) as alive, count(eval(status="dead")) as dead by Animal
| eval diff=alive-dead
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

mockingj
New Member
03-19-2020
07:10 AM
thanks you for your answer
