Splunk Search

regex help!

kiran331
Builder

How to extract the IP OR hostname from the field "source"?

source=/opt/var/log/splunk/ciscoasa/11.12.22.345/2017_06_05_21_cisco.log
source=/opt/var/log/splunk/ciscoasa/abc_xyz/2017_06_05_21_cisco.log

I need to extract 11.12.22.345 & abc_xyz

Tags (2)
0 Karma
1 Solution

inventsekar
SplunkTrust
SplunkTrust

Hi Kiran, Verified and this works fine -

source="ciscoasa.txt" | rex field=_raw "ciscoasa\/(?<ipAddress>.*)\/" | table ipAddress _raw

alt text

View solution in original post

0 Karma

horsefez
Motivator

Hi,

because I was bored I made this redundant answer.

yoursearch | rex field=source "(?<host>[^\/]+)\/[^\/]+(?:$)"

gcusello
SplunkTrust
SplunkTrust

Hi kiran331,
Try this:

your_search | rex field=source "ciscoasa\/(?<host>[^\/]*)" | ...

you can test it at https://regex101.com/r/wrL9Ze/1

Bye.
giuseppe

0 Karma

inventsekar
SplunkTrust
SplunkTrust

Hi Kiran, Verified and this works fine -

source="ciscoasa.txt" | rex field=_raw "ciscoasa\/(?<ipAddress>.*)\/" | table ipAddress _raw

alt text

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...