Splunk Search

split specific values from list

harishalipaka
Motivator

Hi All,

I have data like below

Drive Free_Space

C:,D: 500 GB,450 GB
E:,D: 250 GB,150 GB
C:,E: 250 GB,1 TB
S:,D:,C:,G 120 GB,450 GB,250 GB,800 GB

I want output as

outputimage

Please help me for this urgent
Thank you

Thanks
Harish
0 Karma

manjunathmeti
Champion

Hi @harishalipaka,

Try this query:

| makemv delim="," Drive 
| makemv delim="," Free_Space 
| eval fields = mvzip(Drive,Free_Space) 
| rex field=fields "(?<Drive1>[C]+):,(?<Free_Space1>[\d]+\sGB)" 
| rex field=fields "(?<Drive2>[D]+):,(?<Free_Space2>[\d]+\sGB)" 
| table Drive1, Drive2, Free_Space1, Free_Space2

Sample query:

| makeresults
| eval _raw="Drive Free_Space
C:,D: 500 GB,450 GB
E:,D: 250 GB,150 GB
C:,E: 250 GB,1 TB
S:,D:,C:,G 120 GB,450 GB,250 GB,800 GB"
| multikv forceheader=1
| makemv delim="," Drive
| makemv delim="," Free_Space
| eval fields = mvzip(Drive,Free_Space)
| rex field=fields "(?[C]+):,(?[\d]+\sGB)"
| rex field=fields "(?[D]+):,(?[\d]+\sGB)"
| table Drive1, Drive2, Free_Space1, Free_Space2

0 Karma

darrenfuller
Contributor

Here is my attempt:

| makeresults 
| eval formatted_test_data="|<host1>C:,D: 500 GB,450 GB|<host2>E:,D: 250 GB,150 GB|<host3>C:,E: 250 GB,1 TB|<host4>S:,D:,C:,G: 120 GB,450 GB,250 GB,800 GB|"
| rex field=formatted_test_data "\|(?<test_data>[^\|]+)" max_match=0
| table _time test_data
| mvexpand test_data
| rex field=test_data "<(?<host>\w+)>"

| rex field=test_data "(?<drive>\w\:)" max_match=0
| rex field=test_data "(?<capacity>\d+\s[MGTP]B)" max_match=0
| eval drive_plus_capacity=mvzip(drive, capacity)
| fields - test_data capacity drive
| mvexpand drive_plus_capacity
| rex field=drive_plus_capacity "(?<drive>\w\:)\,(?<freespace>\d+\s[MGTP]B)"
| sort hostname drive
| streamstats count as drivenum by hostname reset_on_change=true
| chart list(drive_plus_capacity) over  hostname by drivenum
| rex field=1 "(?<drive1>\w\:)\,(?<freespace1>\d+\s[MGTP]B)"
| rex field=2 "(?<drive2>\w\:)\,(?<freespace2>\d+\s[MGTP]B)"
| rex field=3 "(?<drive3>\w\:)\,(?<freespace3>\d+\s[MGTP]B)"
| rex field=4 "(?<drive4>\w\:)\,(?<freespace4>\d+\s[MGTP]B)"
| fields - 1 2 3 4

./DF

0 Karma

ajayabburi508
Path Finder

Hi Harish,

try this and if you like please accept and vote my answer

| makemv delim="," Drive| makemv delim="," Free_Space| table Drive Free_Space | eval findC=mvfind(Drive,"C:")| eval findD=mvfind(Drive,"D:")|eval Drive1=mvindex(Drive,findC)|eval Drive2=mvindex(Drive,findD) |eval FreeSpace1=mvindex(Free_Space,findC)|eval FreeSpace2=mvindex(Free_Space,findD)

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...