Splunk Search

Pulling Last Integer Value from Unlabeled Field

ctallarico20
Path Finder

Hi, this is a 3-line sample of my data: What I'm trying to do is get ahold of the last two fields (524288000 and 188077720 in line 1) so I can plot their trends in a graph. How would I go about doing this? I've looked into extract(kv) and kvform and have some limited experience in rex fields, but I'm pretty new to this so any help would be appreciated. Thank you!

34 Mon May 19 13:00:09 EDT 2014 271764960 1 PS MarkSweep 0 0.0 0 0.0 524288000 524288000 524288000 188077720
34 Mon May 19 13:00:09 EDT 2014 271764990 2 PS MarkSweep 0 0.0 0 0.0 521666560 524288000 521666560 186098608
34 Mon May 19 13:00:09 EDT 2014 271764995 3 PS MarkSweep 0 0.0 0 0.0 523763712 524288000 523763712 147496952

Tags (4)
0 Karma
1 Solution

lukejadamec
Super Champion

You should use rex.

your search that produced this output | rex "(?P<firstnumber>\d+)\s+(?P<secondnumber>\d+)$"

The above search should create two new fields called firstnumber and secondnumber.
Edited to include a closing quote.

View solution in original post

lukejadamec
Super Champion

You should use rex.

your search that produced this output | rex "(?P<firstnumber>\d+)\s+(?P<secondnumber>\d+)$"

The above search should create two new fields called firstnumber and secondnumber.
Edited to include a closing quote.

lukejadamec
Super Champion

The $ means "the end of the line", so in this case it give regex an anchor - it tells regex to basically look backwards from the end of the line. The ^ is the symbol for the beginning of the line.

ctallarico20
Path Finder

Yeah, you guys were right! If you don't mind me asking, what does the $ command do? I'd love to understand a little how these results are being found

0 Karma

somesoni2
Revered Legend

Did you miss the "$" sign from the regex?

lukejadamec
Super Champion

I think you forgot the $ at the end.

rex "(?P<firstnumber>\d+)\s+(?P<secondnumber>\d+)\s+(?P<thirdnumber>\d+)\s+(?P<fourthnumber>\d+)\s+(?P<fifthnumber>\d+)$"

ctallarico20
Path Finder

Thanks for the help!
I tried using the rex command
rex "(?P<firstnumber>\d+)\s+(?P<secondnumber>\d+)\s+(?P<thirdnumber>\d+)\s+(?P<fourthnumber>\d+)\s+(?P<fifthnumber>\d+)"
On this search, but I'm getting some weird behavior. In the above example, firstnumber is 19 (as in May 19), secondnumber is 13 (the hour), thirdnumber is 1, 2, or 3 for the respective line, fourthnumber is 524288000, 521666560, 523763712, and fifthnumber is 188077720, 186098608,147496952. As you can see, I'm getting the 4th-to-last as fourthnumber and then skipping to the last for fifthnumber, do you know why?

0 Karma
Get Updates on the Splunk Community!

New This Month in Splunk Observability Cloud - Metrics Usage Analytics, Enhanced K8s ...

The latest enhancements across the Splunk Observability portfolio deliver greater flexibility, better data and ...

Alerting Best Practices: How to Create Good Detectors

At their best, detectors and the alerts they trigger notify teams when applications aren’t performing as ...

Discover Powerful New Features in Splunk Cloud Platform: Enhanced Analytics, ...

Hey Splunky people! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2408. In this ...