Splunk Search

How to keep leading zeros in a numeric field when converting it to string?

fere
Path Finder

I have this as part of my query: eval this_move=tostring(seq)."-."screen
Only I need to make sure seq is treated as 2 digit number before converting to string. Is there a way to do that?

Tags (2)
0 Karma
1 Solution

aholzer
Motivator

This should get you what want you need:

<base search> | eval temp=if(length(seq)<2,"0"+seq,seq) | eval this_move=temp+"-"+screen

I split it into two eval statements to make it easier to understand what's going on, but you can consolidate it into a single eval statement if you prefer.

Note: I assume that "screen" is a string field that you want to concatenate with "seq" field

Hope this helps

View solution in original post

aholzer
Motivator

This should get you what want you need:

<base search> | eval temp=if(length(seq)<2,"0"+seq,seq) | eval this_move=temp+"-"+screen

I split it into two eval statements to make it easier to understand what's going on, but you can consolidate it into a single eval statement if you prefer.

Note: I assume that "screen" is a string field that you want to concatenate with "seq" field

Hope this helps

fere
Path Finder

thanks for your help

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...