Splunk Search

How to extract LAT and LONG from a string?

changux
Builder

Hi all.

I have a field with:

Address=DG 14 KR 36 A 90 LAT:14.752811 LON:-79.543

I need to create three fields from here:

Address=DG 14 KR 36 A 90
LAT=14.752811
LON=-79.543

I know the regexes for LAT and LONG:

For LAT: (?<=LAT:)(-?\d+\.\d+)
For LON: (?<=LON:)([\d.-]+)

Address must be all the string before LAT word.

I tried to LAT and LON:

... | field="Address" "(?<LAT>.(?<=LAT:)(-?\d+\.\d+))\.(?<LON>.(?<=LON:)([\d.-]+))"

But doesn't work. Any idea? Also, I need extract the address.

0 Karma
1 Solution

javiergn
SplunkTrust
SplunkTrust

Hi,

My proposal that includes case insensitive checks and non-greedy evaluation:

| rex field=Address "(?i)^Address=(?<Address>.+?)\s+LAT:\s*(?<LAT>[\-\d\.]+)\s+LON:\s*(?<LON>[\-\d\.]+)\s*$"

View solution in original post

chimell
Motivator

Hi
try this search code

 ... |rex  field=Address   "(LAT\:(?<LAT>[^\s+]+)\s+(LON\:(?<LON>[^\s+]+)$"

javiergn
SplunkTrust
SplunkTrust

Hi,

My proposal that includes case insensitive checks and non-greedy evaluation:

| rex field=Address "(?i)^Address=(?<Address>.+?)\s+LAT:\s*(?<LAT>[\-\d\.]+)\s+LON:\s*(?<LON>[\-\d\.]+)\s*$"

muebel
SplunkTrust
SplunkTrust

Hi changux, try this regex:

^Address=(?<address>.*)\sLAT:(?<lat>.*)\sLON:(?<lon>.*)$

you can do inline field extraction after you've gotten the initial events by piping to the rex command like so:

| rex field=Address "^Address=(?<address>.*)\sLAT:(?<lat>.*)\sLON:(?<lon>.*)$"

Please let me know how this goes for you!

Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...