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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...