Splunk Search

Using regex to extract word after semicolons

TCK101
New Member

Hi

I am attempt to extra host names from logs they always appear after the 4th semicolon :

E.g. I want the extra the "hostname" as a field and ignore all the characters and spaces before the 4th semicolon (:)

May 19 10:09:41 server1 Device: Script Completed Successfully: hostname1
May 19 11:13:01 server2 Device: Script Completed Successfully: hostname2
May 19 17:09:21 server3 Device: Script Completed Successfully: hostname3

Tags (3)
0 Karma
1 Solution

bishtk
Communicator

You can use Field Extractor and then choose Regex and highlight the hostname part after selecting a sample event from your search.
Also same can be achieved by delimiter method and then you can remove unwanted extractions and can only keep hostname extraction i.e. after 4th semicolon as you have mentioned.
Regex will suit you best here.
For more information refer this link
http://docs.splunk.com/Documentation/Splunk/6.6.0/Knowledge/FXSelectSamplestep

View solution in original post

0 Karma

niketn
Legend

This could be one of the easiest regular expression, however there are multiple options.

your base search 
| rex field=_raw "Script Completed Successfully: (?<hostname>.*)"
| table hostname _raw

Once you have tested the Regular Expression you should move the same to Field Extractions using props.conf.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

bishtk
Communicator

You can use Field Extractor and then choose Regex and highlight the hostname part after selecting a sample event from your search.
Also same can be achieved by delimiter method and then you can remove unwanted extractions and can only keep hostname extraction i.e. after 4th semicolon as you have mentioned.
Regex will suit you best here.
For more information refer this link
http://docs.splunk.com/Documentation/Splunk/6.6.0/Knowledge/FXSelectSamplestep

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...