Splunk Search

How to search for specific text in field without additional text?

joesrepsol
Path Finder

Sorry for the strange title... couldn't think of anything better. Doing a search on a command field in Splunk with values like:
sudo su - somename
sudo su - another_name
sudo su -

And I'm only looking for the records "sudo su -". I don't want the records that match those characters and more... just records that ONLY contain "sudo su -". When I write the search Command="sudo su -" I still get the other records too. Struggling to figure this out.

Thanks!

Tags (1)
0 Karma
1 Solution

DalJeanis
Legend

There are lots of ways to make this happen.

You could use a sed mode rex to eliminate the part you don't care about, and if anything is left, keep the record...

your search that gets all the "sudo su -"  (and remember there may be extra spaces...)
| eval testfield=Command
| rex mode=sed field=testfield "s/sudo\s+su\s+-//"
| where testfield!=""

You could use a regular expression that will only match if there are non-whitespace characters after the -

your search that gets all the "sudo su -"  (and remember there may be extra spaces...)
| regex Command="\s*sudo\s+su\s+-[ \t]*\w"

View solution in original post

0 Karma

DalJeanis
Legend

There are lots of ways to make this happen.

You could use a sed mode rex to eliminate the part you don't care about, and if anything is left, keep the record...

your search that gets all the "sudo su -"  (and remember there may be extra spaces...)
| eval testfield=Command
| rex mode=sed field=testfield "s/sudo\s+su\s+-//"
| where testfield!=""

You could use a regular expression that will only match if there are non-whitespace characters after the -

your search that gets all the "sudo su -"  (and remember there may be extra spaces...)
| regex Command="\s*sudo\s+su\s+-[ \t]*\w"
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@joesrepsol

have you tried search command?

try this:

| makeresults | eval _raw=" Command
sudo su - somename
sudo su - another_name
sudo su -
" | multikv | search Command="sudo su -"
0 Karma

joesrepsol
Path Finder

THANK YOU.

This seems to have worked! I'm a little confused why adding Command="sudo su -" in the normal search seemingly applies an asterisks to the value, but when adding it with the |search Command="sudo su -" doesnt?

Regardless its working, and thank you.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Great.

Can you please accept the answer and upvote it to help the community?

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...