Splunk Search

How to remove everything after a specific character in a line

rijinc
Explorer

Currently i am not familiar with REx and replace commands in splunk. Can someone help me here
i want to replace to blank anything after fullstop

for ex :
Username
A1B1.;#12345

;#12345 this character needs to be removed.

Tags (1)
0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

| rex field=Username mode=sed "s/\..*$//"

View solution in original post

woodcock
Esteemed Legend

Like this:

| rex field=Username mode=sed "s/\..*$//"

rijinc
Explorer

Thanks Sir....it worked 🙂

0 Karma

sylinttest
New Member

I have a similar issue, in the Message field from a specific event code from the WinEventLogs it says

"A memeber was added to a security-enabled global group."
Subject:
Security ID:

I want everything after the period "group." gone. I tried the above rex however nothing changed.

0 Karma

to4kawa
Ultra Champion

(?s)
try this option.

0 Karma

sylinttest
New Member

I sorry I am very new to splunk where should I put that option in the search?

0 Karma

to4kawa
Ultra Champion
| makeresults
| eval _raw="\"A memeber was added to a security-enabled global group.\"
Subject:
Security ID:"
 | rex mode=sed "s/(?s)\..*$/./"

cf. regex101

0 Karma

to4kawa
Ultra Champion
| makeresults
| eval _raw="\"A memeber was added to a security-enabled global group.\"
 Subject:
 Security ID:"
 | rex "\"(?<_raw>.+)\""

I will do it like this.

0 Karma

rijinc
Explorer

i have got another requirement where

for ex :
Username
Lynn Chriss H;#12345

need to remove the values from full stop [;#12345] was tryin to use the above rex by interchanging some thing like this. It doesnt work ...
| rex field="Username" mode=sed "s/[A-Z]*$//"
?
Request your help on this

0 Karma

woodcock
Esteemed Legend

Oh, I see, my original answer also removed the . but you need to keep that, just do this:

 | rex field=Username mode=sed "s/\..*$/./"
0 Karma
Get Updates on the Splunk Community!

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 ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...