Splunk Search

Need help on rtrim command

nnimbe1
Path Finder

Hi Team,

I am using rtrim command to trim some values, but its not working for all the values,as per below screenshot i need to trim everything from _-D in all values, its working for first one for remaining values its not working, can anyone please provide some solution to it. Or in case of any regex please suggest

sap process error.JPG 

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The rtrim command (and ltrim and trim as well) do not take regular expressions.  The second argument is a list of characters that will be removed.  In the example, four characters will be removed if present: underscore, hyphen, upper-case D, and asterisk.

To remove characters based on a regular expression, use rex mode=sed.

---
If this reply helps you, Karma would be appreciated.
0 Karma

nnimbe1
Path Finder

@richgalloway  Thanks, but if you can help with rex expression using which if i can exclude everything from _ -D in all values then it will be helpful

0 Karma

vijetagalani
Observer

@nnimbe1 You can try the below search. The reason rtrim is working only for few is that you need to specify complete string that needs to be truncated from right. You can either use the rex command or use split and mvindex to get the desired result

index=linux host=*  source=ps sapstasrtsrv| eval temp=split(ARGS,"_-d")|eval ARGS=mvindex(temp,0)

.  

0 Karma

nnimbe1
Path Finder

@vijetagalani , thanks but unfortunately its not working, if you can help me with rex expression using which i can exclude everything from _-D in ARGS  field then it will be helpful

 

sap11.JPG

0 Karma

nnimbe1
Path Finder

@ITWhisperer ,thanks but unfortunately its not working, if you can help me with rex expression using which i can exclude everything from _-D in ARGS  field then it will be helpfulsap12.JPG

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

The fact that you are not getting any events has nothing to do with the rex, your base search

index=linux host=* source=ps sapstasrtsrv

is not returning any events for the 24 hour time period you specified. Fix this and reapply the rex

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
...
| rex field=ARGS "(?<ARGS>.*)_-D"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...