Splunk Search

Create new fields based on value of another fields.

paragvidhi
Engager

Hi All,
In my log, I have one field called ServerName. Below are some values of that field.

DAAPP2aBANG2
DFAPP20bLON2
UATSER1aUS1
UATSER1bUS2

We differentiate the above server with node A and node B based on the first character we got after the first occurrence of one or more digit.

DAAPP2aBANG2 -- its node a
DFAPP20bLON2 --- its node b
UATSER1aUS1 --- its node a
UATSER1bUS2 --- its node b

Here I want to create two fields called NodeA, and NodeB

In NodeA it should contain DAAPP2aBANG2 ,UATSER1aUS1
In NodeB it should contain DFAPP20bLON2, UATSER1bUS2

Tags (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @paragvidhi,
you could try something like this:

index=your_index
| rex field=ServerName "\w+\d(?<Node>a|b)"
| eval Node="Node ".Node
| table ServerName Node

You can test the regex at https://regex101.com/r/jLeU1f/1

Ciao.
Giuseppe

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...