Splunk Search

strip off a part of a search field

sugethakch
New Member

I have a search query that goes like this:
sourcetype="inv" Inv name=* | table name, intf, model, serialnum, mfgname | dedup switchname intf | stats count by ....

I want to do, stats counts by name in this case. If I search by intf=*, then I want to do, stat count by intf and so on.

I tried something like this,
sourcetype="inv" Inv name=* | table name, intf, model, serialnum, mfgname | dedup switchname intf | eval n=rtrim("name=","=") | stats count by n

But, that didn't work. I see why. But, how do I achieve that?

0 Karma

woodcock
Esteemed Legend

I would use a macro like this in macros.conf:

[MyMacro(1)]
args = fieldname
definition = sourcetype="inv" Inv $fieldname$=* | table name, intf, model, serialnum, mfgname | dedup switchname intf | stats count by $fieldname$

Then call it like this:
... | `MyMacro(name)`
And like this:
... | `MyMacro(intf)`

0 Karma

musskopf
Builder

Just trying to understand the context and your use case... as you'll be changing the first part of the search anyway, why don't update the last bit at same time?

0 Karma

vganjare
Builder

Can macro help in this case?

0 Karma
Get Updates on the Splunk Community!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...