Splunk Search

Hide a column based on search criteria

sahil237888
Path Finder

I want to hide a column based on some search.

I have three columns.
Host, Value , Unit

If(host=abc)
then hide the "value" column and only display column "unit ".
If (host=xyz)
then hide the "unit" column and display only "value" column.

Tags (1)
0 Karma

horsefez
Motivator

hey @sahil237888,

how about something like this

<your search> | eval Value=if(host=="abc",null(),Value) | where isnotnull(Value) | table Host, Value, Unit

Try that one, and tell me how it goes.

Best regards,
pyro_wood

0 Karma

sahil237888
Path Finder

Hi @pyro_wood,

Thanks.
but it is not hiding columns however it makes them empty.
Is there any way it could be hidden?

0 Karma

renjith_nair
Legend

Hi @sahil237888,

Just out of curiosity, why do you want to hide the column ? what happens if you just mentions "Not Applicable(N/A) based on the host? Hows does it appear in a tabular format according to you ?

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

sahil237888
Path Finder

if i will put n/a it will also come in my search.
and if i will hide i will not get column that is irrelevant.

hope I am clear.

0 Karma

niketn
Legend

@sahil237888, how about something like the following:

| eval data=case(host=="abc",unit,host=="xyz",value)
| table host data

Following is a run anywhere search:

| makeresults
| eval data="host=abc,value=123,unit=aa;host=xyz,value=234,unit=bb;"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| KV
| eval data=case(host=="abc",unit,host=="xyz",value)
| table host data
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

sahil237888
Path Finder

@niketnilay,
I have tried but it is not hiding any column.

Can you suggest something else.

0 Karma

somesoni2
Revered Legend

What should be the expected output? Can you show the final table you expect?
You can't hide a column for just for one row and show for other row. If a column is present for any of the row , that column will be shown for whole table.

0 Karma

sahil237888
Path Finder

_Time Host Ecnt PingTime Availability
17-08-18 8:09 A 5 400 Available
17-08-18 8:10 B 8 8 Not Available
17-08-18 8:11 C 4 4 Down
17-08-18 8:12 D 0 100 Available
17-08-18 8:13 E 1 600 Available
17-08-18 8:14 F 7 7 Not Available
17-08-18 8:15 G 8 500 Down
17-08-18 8:16 H 0 3100 Down
17-08-18 8:17 I 4 8 Not Available
17-08-18 8:18 J 7 600 Down
17-08-18 8:19 K 5 500 Available
17-08-18 8:20 L 4 586 Available
17-08-18 8:21 M 0 754 Not Available
17-08-18 8:22 N 6 421 Down
17-08-18 8:23 O 7 856 Available
17-08-18 8:24 P 7 0 Down

This is the sample table. Now My requirement is :

If Ecnt > 5
Display _time,Host, Ecnt,PingTime
Else
Hide Ecnt column

If PingTime >1000
Display _time,Host,PingTime,Ecnt,Availability
Else
hide PingTime column

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...