Splunk Search

How do you use regex to remove duplicate characters?

mistydennis
Communicator

I have a report that requires several fields to be concatenated, each separated by a semicolon. Because some of the fields are null, the values look like this:

cat; dog; ; ; ; snake; bird; ; hamster; ; ;

I want the field to look like this:

cat; dog; snake; bird; hamster

Is there a way to use regex to remove the duplicate semicolons? I'd also like to make sure the field does not end with a semicolon.

Open to other ideas if regex is not the best solution.

Tags (2)
1 Solution

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval msg="cat; dog; ; ; ; snake; bird; ; hamster; ; ;" 
| makemv delim=";" msg 
| eval msg= ltrim(msg) 
| eval msg=mvjoin(mvfilter(msg!=""),";")

View solution in original post

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval msg="cat; dog; ; ; ; snake; bird; ; hamster; ; ;" 
| makemv delim=";" msg 
| eval msg= ltrim(msg) 
| eval msg=mvjoin(mvfilter(msg!=""),";")

mistydennis
Communicator

YES! Thank you so much!

0 Karma
Get Updates on the Splunk Community!

AppDynamics Summer Webinars

This summer, our mighty AppDynamics team is cooking up some delicious content on YouTube Live to satiate your ...

SOCin’ it to you at Splunk University

Splunk University is expanding its instructor-led learning portfolio with dedicated Security tracks at .conf25 ...

Credit Card Data Protection & PCI Compliance with Splunk Edge Processor

Organizations handling credit card transactions know that PCI DSS compliance is both critical and complex. The ...