Splunk Search

Need help with REX, PLEASE

nathbe01
Explorer

Hello, I am new to using REX wich is I believe is what I need. I have a field that has data that looks like this...

10.231.247.162--WTLDNDAA001--Can't ping DSLAM
10.44.69.250--TCSUAZMS--VisibilityOnly--Can't ping DSLAM 
10.44.69.250--TCSUAZMS--Can't ping DSLAM--VisibilityOnly 
172.31.247.148--CLSPCO32H01.2--Can't ping DSLAM 
172.31.166.155--RSBGORBU--Can't ping DSLAM 


I want my table to ONLY show whats between the hyphens

Example I want to get 
WTLDNDAA-001

TCSUAZMS

CLSPCO32H01.2

RSBGORBU

Can anybody help me with creating a rex that removes everything not between the the 2 sets of hyphens.

Would be greatly appreciated!!

Labels (3)
0 Karma
1 Solution

bshuler_splunk
Splunk Employee
Splunk Employee

The regex I would use is :

 

--(?<myfield>[^-\n]+)--

 

You can see it in action here:

 

https://regex101.com/r/AbOMKk/1

 

or you can test it with SPL here:

| makeresults | eval data=split("10.231.247.162--WTLDNDAA001--Can't ping DSLAM%%10.44.69.250--TCSUAZMS--VisibilityOnly--Can't ping DSLAM%%10.44.69.250--TCSUAZMS--Can't ping DSLAM--VisibilityOnly%%172.31.247.148--CLSPCO32H01.2--Can't ping DSLAM%%172.31.166.155--RSBGORBU--Can't ping DSLAM", "%%")| mvexpand data | rex field=data "--(?<myfield>[^-\n]+)--"

 

but as this looks like you are extracting the host, I would recommend using a props/transforms combination:

props.conf

[mysourcetype]
TRANSFORMS-hostoverride=mysourcetype_hostoverride

 

transforms.conf

[mysourcetype_hostoverride]
DEST_KEY = MetaData:Host
REGEX = ^\d+\.\d+\.\d+\.\d+--(?<myfield>[^-\n]+)--
FORMAT = host::$1

 

This regex can be tested here:

https://regex101.com/r/AbOMKk/2

View solution in original post

bshuler_splunk
Splunk Employee
Splunk Employee

The regex I would use is :

 

--(?<myfield>[^-\n]+)--

 

You can see it in action here:

 

https://regex101.com/r/AbOMKk/1

 

or you can test it with SPL here:

| makeresults | eval data=split("10.231.247.162--WTLDNDAA001--Can't ping DSLAM%%10.44.69.250--TCSUAZMS--VisibilityOnly--Can't ping DSLAM%%10.44.69.250--TCSUAZMS--Can't ping DSLAM--VisibilityOnly%%172.31.247.148--CLSPCO32H01.2--Can't ping DSLAM%%172.31.166.155--RSBGORBU--Can't ping DSLAM", "%%")| mvexpand data | rex field=data "--(?<myfield>[^-\n]+)--"

 

but as this looks like you are extracting the host, I would recommend using a props/transforms combination:

props.conf

[mysourcetype]
TRANSFORMS-hostoverride=mysourcetype_hostoverride

 

transforms.conf

[mysourcetype_hostoverride]
DEST_KEY = MetaData:Host
REGEX = ^\d+\.\d+\.\d+\.\d+--(?<myfield>[^-\n]+)--
FORMAT = host::$1

 

This regex can be tested here:

https://regex101.com/r/AbOMKk/2

nathbe01
Explorer

That worked, Thank you

0 Karma
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...