Splunk Search

How do I edit my regex to capture the shortname from a mix of FQDN and shortname host field entries?

renems
Communicator

I'm trying to create a new field based on the host field. The new field (hostname) should only contain the shortname. The host field is currently a mix of fqdn and shortnames:

server1.linux.splunk.co.uk
server2.linux.splunk.co.uk
server3
server4.linux.splunk.co.uk

So far, this comes close to what I'm trying to achieve:

| rex field=host "(?P<hostname>[^ ]+?)\."

Works great for all entries that actually do have a dot (.) in the text (number1, 2, 4). The ones without a dot (.) return blank. How do I also include the ones that don't need modification at all? (number 3)

Any help greatly appreciated!

0 Karma
1 Solution

ltrand
Contributor

It's too greedy to put against just a block of text, but as long as the field is sanitary, this should work:

(?P<hostname>[^.]+)

View solution in original post

ltrand
Contributor

It's too greedy to put against just a block of text, but as long as the field is sanitary, this should work:

(?P<hostname>[^.]+)

renems
Communicator

It does! Kudo's for you, my friend!

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 ...