Splunk Search

Extract last field from pair of lines in a log file

smurf4568
New Member

Data looks like this

# grep 28969 request.log
22/Jul/2016:15:09:54 +0200 [28969] -> GET /libs/granite/csrf/token.json HTTP/1.1
22/Jul/2016:15:09:54 +0200 [28969] <- 200 application/json 4ms

[xxxxxx] is the common (field extracted as RequestID)

lines where -> GET exist, I want to return the URL (field extracted as URL)
lines where <- [0-9][0-9][0-9] is present, I want to return just the final field (4ms) as RequestTime

Result should look like

28969 /libs/granite/csrf/token.json 4ms

0 Karma

sundareshr
Legend

Or this

... | rex "GET\s(?<URL>[^\s]+)" | rex "(?<RequestTime>\w+)$" | stats values(URL) as URL values(RequestTime) as RequestTime by RequestID
0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

your base search | rex "\]\s(-\>\s+GET+\s(?<URL>[^\s]+)" | rex "\]\s(-\>\s+([0]{3})+\s([^\s]+)(?<RequestTime>\w+)" | stats values(URL) as URL values(RequestTime) as RequestTime by RequestID
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 ...