Splunk Search

how to reverse field value in Splunk

joomla
Engager

Hi Team,

 

I have a field name domain with value "www.microsoft.com"; how I can reverse that and make it to "com.microsoft.www"

 

domain=www.microsoft.com

required: domain=com.microsoft.www

 

Many Thanks.

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This is a new one to me.  If the domain is always 3 parts you can split the domain then use foreach to put the pieces back together in reverse order as in this run-anywhere example.

| makeresults 
| eval domain="www.microsoft.com" 
``` Above just creates demo data ```
``` Break the domain at each dot ```
| eval foo=split(domain,".") 
``` Iterate over the segments in reverse order and put them together ```
| foreach 2 1 0 [ eval rev_domain=mvjoin(mvappend(rev_domain,mvindex(foo,<<FIELD>>)),".")] 
| table domain rev_domain
---
If this reply helps you, Karma would be appreciated.
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @joomla,

if the structure is fixed, you can use a regex, otherwise I suppose that it isn't possible:

<your_search>
| rex field=domain "^(?<part1>[^\.]+)\.^(?<part2>[^\.]+)\.^(?<part3>[^\.]+)"
| eval new_domain=part3.".".part2.".".part1
| table domain new_domain

Ciao.

Giuseppe

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval _domain=split(domain,".")
| foreach mode=multivalue _domain
    [| eval dom=if(isnull(dom),<<ITEM>>,<<ITEM>>.".".dom)]
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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...