Splunk Search

how to split string in splunk

Khushboo
Explorer

Hi @all,

 

i have following string which i want to break into there fields: service_name, host and port_id

metics-ha-5924590-011.aba.corp.tyos.com:2002

service_name = metics

host = ha-5924590-011.aba.corp.tyos.com

port = 2002
anyone please help me, how can i do it in splunk query.

Thanks !!

Labels (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Khushboo,

you have to define a rule to extract fields:

if you cadn define that:

  • from the beginning to the first "-" it's the "service_name",
  • from the service_name to ":" it's the host,
  • after there's the port;

this regex can work.

In other words if you can define a rule, you can use a regex otherwise you cannot!

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @Khushboo,

Please, try this regex:

| rex "(?<service_name>[^-]+)-(?<host>[^:]+):(?<port>\d+)"

tha you can test at https://regex101.com/r/wkUHCx/1

Ciao.

Giuseppe

Khushboo
Explorer

Hi @gcusello ,

Thanks for your reply.
In my case all the variables like service_name, host and port are dynamic. so i cant hard-coded that.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Khushboo,

you have to define a rule to extract fields:

if you cadn define that:

  • from the beginning to the first "-" it's the "service_name",
  • from the service_name to ":" it's the host,
  • after there's the port;

this regex can work.

In other words if you can define a rule, you can use a regex otherwise you cannot!

Ciao.

Giuseppe

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...