Splunk Enterprise Security

How to convert String to Integer search?

umesh
Path Finder

Hi team,

I have "file_size" in my  extracted fields and the values are 1.56 KB,5.03 MB, 1.06 B. and those values are strings. I need a query how to convert string to Integer to sum(file_size)  i need to use max and min and sum commands for the file_size. Please help me on the same.

 

Thanks

Tags (3)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Here's an example - you need the rex and eval statements

| makeresults
| eval file_size=split("1.56 KB,5.03 MB,1.06 B,1MB,4.95 GB,5.13TB", ",")
| mvexpand file_size
| rex field=file_size "(?<size>\d+(\.\d+)?)\s?(?<mul>\w+)?"
| eval file_size=case(mul="KB", size * 1024, 
                      mul="MB", size * 1024 * 1024, 
                      mul="GB", size * 1024 * 1024 * 1024, 
                      mul="TB", size * 1024 * 1024 * 1024 * 1024,
                      1==1, size)
0 Karma
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 ...