Splunk Search

How to convert version number so the dots are consistent

splunkyj
Path Finder

See the example values below. How do I convert the value of the version field, so that they have the same number of decimals?

version=7.3.2

version=8.0.2.1

I would like this to be converted to:

version=7.3.2.0

version=8.0.2.1

Labels (2)
0 Karma
1 Solution

to4kawa
Ultra Champion
| makeresults 
| eval version="7.3.2" | appendpipe [| eval version="8.0.2.1" |appendpipe [eval version="7.2"|appendpipe [eval version="7"]]]
| eval count=mvcount(split(version,"."))
| eval version=version.substr(".0.0.0.0",1,(abs(count - 4) * 2) )

Maybe it's easier this way.

View solution in original post

to4kawa
Ultra Champion
| makeresults 
| eval version="7.3.2" | appendpipe[eval version="8.0.2.1" | appendpipe[eval version="7.2"| appendpipe[eval version="7"]]] 
| eval versions=mvindex(mvappend(split(version,"."),split("0000000","")),0,3)
| eval version=mvjoin(versions,".")

I couldn't make it with regular expressions.

0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval version="7.3.2" | appendpipe [| eval version="8.0.2.1" |appendpipe [eval version="7.2"|appendpipe [eval version="7"]]]
| eval count=mvcount(split(version,"."))
| eval version=version.substr(".0.0.0.0",1,(abs(count - 4) * 2) )

Maybe it's easier this way.

splunkyj
Path Finder

@to4kawa thank you so much again!! You rock! Both worked, I just went with this one because it's simpler. Or looked to be, let me know if the other one is more efficient. But they both worked well! One day I wanna be like you 🙂

0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval version="7.3.2" | appendpipe [| eval version="8.0.2.1"]
| rex field=version mode=sed "s/\b(\d)\b/0\1/g s/\.//g"
| eval version=substr(version."0000000",1,8)
| rex field=version mode=sed "s/(\d\d)/\1./g s/0(\d)\b/\1/g s/\.$//"

I want the shift instruction.

Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...