Splunk Search

How to get Splunk btool command to return an exact match?

lukasz92
Communicator

Hi,

I have savedsearches like:

dev_sudo
dev_sudo mod
dev_sudo mod2

How to dump the first with btool?
If I use splunk cmd btool savedsearches list dev_sudo - I get all three results. I need to dump only exact match

0 Karma
1 Solution

lukasz92
Communicator

If somebody will need it, something like this should work:

| sed 's/^[^ ]\+ \+//g' | tr '\n' '~' | sed 's/^\(\[[^\[]\+\).*/\1/g' | tr '~' '\n'

It assumes that the exact match will be first.

View solution in original post

0 Karma

bandit
Motivator

I like grep -P

-P, --perl-regexp
Interpret the pattern as a Perl-compatible regular expression (PCRE).

splunk cmd btool savedsearches list | grep -P "dev_sudo$"

and if you are only looking to scrape the matching regex...
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

splunk cmd btool savedsearches list  | grep -Po "dev_sudo$"
0 Karma

lukasz92
Communicator

If somebody will need it, something like this should work:

| sed 's/^[^ ]\+ \+//g' | tr '\n' '~' | sed 's/^\(\[[^\[]\+\).*/\1/g' | tr '~' '\n'

It assumes that the exact match will be first.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I'm not sure you can. The help for btool says " btool [options] CONF_FILE {list|layer|add|delete} [stanzaPrefix]", which tells me btool adds an implicit "*" to the last argument. For example, "splunk btool savedsearches list dev_sudo*".

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...