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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...