Spread our blog

Decimal (base10) numbers into ASCII string format (base36)

In Splunk we can convert any text encoded ASCII string into a decimal number (base10), which is a numeric representation, using an eval function known as “tonumber”. But there are no other options to do the opposite one.

In this blog, we will convert decimal (base10) numbers into ASCII string format (base36).

In this blog, we will demonstrate the two best possible ways to do the above requirements.

Part 1: “Using SPL Query”

We have a field called “OrderNo”, which is in decimal numbers. We will convert that decimal into base36.

index="demo" sourcetype="orderNo" 
| table OrderNo,Owner 
| eval x=OrderNo,power=mvrange(0,21) 
| mvexpand power 
| eval base2=pow(36,power) 
| where x>=base2 
| eval div=floor(x/base2), 
| stats max(x) as x, list(bin) as bin, list(mybin) as mybin by OrderNo,Owner 
| mvcombine delim="" mybin 
| eval M=mvindex(split(mybin," "),0),
    N=mvindex(split(mybin," "),1),
    O=mvindex(split(mybin," "),2),
    P=mvindex(split(mybin," "),3),
    Q=mvindex(split(mybin," "),4),
| fields OrderNo,Owner,base36



Due to the size of the query, we will explain by the line number (which is available in the above figure) for better understanding.

Line1: we took the data from index “demo” and a sourcetype called “orderNo”.

Line2: then using the table command we tabled “orderNo” and “owner” field

Line3: then we create a field called “x” which is the same as “orderNo ” and using the “mvrange” function we created a field called “power”, which will consist of values from o to 21.

Line4: using “mvexpand” we had expanded the “power” field into a single-valued field.

You can also know about :  Splunk Benefits to Coca-Cola: Data-driven insight and help to the IT department

Line5: then using the “eval” command we created a field called “base2” using the “pow” function. Which will basically consider “power” as a power of 36 and will calculate that value within the “base2” field.

Line6: using where command we are considering only those rows where “X”(i.e. orderNo) is greater than equal to “base2”.

Line7: then in the “div” field we are calculating “x” divided by “base2” and using floor function we are considering the nearest whole integer of that calculated value.

Line8: in the “bin” field we are calculating the modulus of the “div” (dividend) field with 36 (divisor). And creating a field called “binx” with the same value of “bin”.

Line9: then we are creating a field called “mybin”, then using the case function we are converting “bin” which is in decimal, into “base36”.

Line10: then using we grouped all the fields using stats command by “orderNo” and “owner” field.

Line11: using the “mvcombine” command we combined the “mybin” field.

Line12: using eval command we created four fields called “M,N,O and P ” where we are splitting values of “mybin” one by one.

Line13: finally we are creating a field called “base36“, where we are concatenating “” and then “P,O,N and M” respectively. And using the fields command we are only taking required fields.

You can also know about :  Porsche is Bringing Data to Everything with Splunk

Hope you have enjoyed this blog, we will come back with new topics of Splunk. Until then goodbye and stay safe and strong.

Happy Splunking !!

What’s your Reaction?

Spread our blog


Please enter your comment!
Please enter your name here