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

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !

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

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...