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!

How to Monitor Google Kubernetes Engine (GKE)

We’ve looked at how to integrate Kubernetes environments with Splunk Observability Cloud, but what about ...

Index This | How can you make 45 using only 4?

October 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

Splunk Education Goes to Washington | Splunk GovSummit 2024

If you’re in the Washington, D.C. area, this is your opportunity to take your career and Splunk skills to the ...