Splunk Search

How to extract words and digits from a particular field

majek81
New Member

Hello everyone,

I am trying to extract strings containing SAMM #2222-A-1111 from other strings in a field named SAMU .
This is what I have entered:

SAMU="SAMM*" "#2*" "-*" 

It works but also output other strings that I don't want to see.
Any suggestions?

0 Karma
1 Solution

aberkow
Builder

I have two thoughts:

1) You can try double searching on SAMU, like so:
SAMU="SAMM*" SAMU="*#2222-A-1111*" (not the best)

2) Use regex:
| makeresults count=3
| streamstats count
| eval fieldToAlertOn=case(count=1, "potato SAMM potato potato #2222-A-1111 potato", count=2, "SAMM #3333-A-1111", count=3, "potato SAM potato #2222")
| regex fieldToAlertOn=".*(?SAMM).*(?\#2222-A-1111).*"

If you run this you can see that only the row with both of those values sticks around. Also not the cleanest solution, but you can be more selective with what you're allowing if you're more familiar with regex (changing specific numbers to number characters, etc).

View solution in original post

0 Karma

aberkow
Builder

I have two thoughts:

1) You can try double searching on SAMU, like so:
SAMU="SAMM*" SAMU="*#2222-A-1111*" (not the best)

2) Use regex:
| makeresults count=3
| streamstats count
| eval fieldToAlertOn=case(count=1, "potato SAMM potato potato #2222-A-1111 potato", count=2, "SAMM #3333-A-1111", count=3, "potato SAM potato #2222")
| regex fieldToAlertOn=".*(?SAMM).*(?\#2222-A-1111).*"

If you run this you can see that only the row with both of those values sticks around. Also not the cleanest solution, but you can be more selective with what you're allowing if you're more familiar with regex (changing specific numbers to number characters, etc).

0 Karma

majek81
New Member

Wow awesome code, it didn't quite give me the result I wanted but it does have some other use-cases.
Perhaps a little simplistic, but this is what work for me
sourcetype=some_sourcetype |mvexpand SAMU| search SAMU="SAMM*" " #20*" "-*"

0 Karma

woodcock
Esteemed Legend

Come back and UpVote this answer, then post your own answer and click Accept on it to close the question.

0 Karma
Get Updates on the Splunk Community!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...