Splunk Search

How to convert this string to a numeric value?

abutler1
New Member

I've created a new field, however, it's appearing as a string instead of a value. I've used the regular expression to extract from the following data:

(?=[^T]*(?:Transfer complete.|T.*Transfer complete.))^[^\.\n]*\.\s+(?P\d+,\d+)

Transfer complete. 1,011 bytes transferred

Therefore building a result of 1,011, however, this is considered a string rather than a numeric value. How can I convert this to treat the result as a numeric value?

0 Karma
1 Solution

sundareshr
Legend

Like this

| gentimes start=-1 | eval x="Transfer complete. 1,011 bytes transferred" | rex field=x "complete\.\s?(?<b>[^\s]+)" | table b | convert num(b) as bn

View solution in original post

sundareshr
Legend

Like this

| gentimes start=-1 | eval x="Transfer complete. 1,011 bytes transferred" | rex field=x "complete\.\s?(?<b>[^\s]+)" | table b | convert num(b) as bn

abutler1
New Member

Apoliges, im a newbie at this and entered the above into the regular expression
it's providing null as a result, the value of bytes transferred will range from line to line

Original Source Line

[21] Thu 14Jul16 14:17:15 - (014058) 226 Transfer complete. 1,011 bytes transferred. 30.85 KB/sec.

Result was null

0 Karma

somesoni2
SplunkTrust
SplunkTrust

You can use your original regex and add the convert command as specified in the answer.

0 Karma

sundareshr
Legend

As long as the bytes is has complete. before it, this regex will capture all combinations. So you search will look like this

... | rex field=x "complete\.\s?(?<bytes>[^\s]+)\sbytes" | convert num(bytes) as bytes
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 ...