Splunk Search

How to create a new field from the value of another field?

rwiley
Explorer

i have a search with these results.

description,     stringValue
datetime,        "epoc time"
zone,            "zonename"
network,         "networkname"
etc,             etc

i want to create a field called date from string value when description = datetime and a field called NetworkZone from stringvalue when description = network get stringvalue "_" when value = zone get string value

so datetime form date time and "network_zone" from network and zone.

i have used eval to combine fields but not to use the values as a new field. not sure if it is possible. thanks for any help.

0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi rwiley,
try something like this:

| eval date=if(description="datetime",stringValue,""), NetworkZone=if(description="network","__",if(value="zone",stringValue,"") 

I'm not sure to have understood the second condition.
Bye.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi rwiley,
try something like this:

| eval date=if(description="datetime",stringValue,""), NetworkZone=if(description="network","__",if(value="zone",stringValue,"") 

I'm not sure to have understood the second condition.
Bye.
Giuseppe

rwiley
Explorer

this is getting the fields created. the networkzone field is only bringing in the underscore. i am working with it to see if it will give me exactly what i need. thanks.

0 Karma

somesoni2
Revered Legend

How about this? This should create a new field with name same as value of the field description and value of this new field will be same as field stringValue.

your base search | eval "{description}"=stringValue
0 Karma

rwiley
Explorer

that will create a new field but i only want the value of stringvalue when the description = a certain value.

so i need a field called network_zone where it only pulls the network name and zone name. and a date field that only gets the stringValue when description = date. something like this.

decription, stringValue
date, date
network, networkname
zone, zonename

new fields
date, netoworkzone
date, "networkname"+"_"+"zonename"

0 Karma

somesoni2
Revered Legend

In that case, you will need to create a separate eval for each new field which will populate it conditionally. Also, you want to merge two events which has network and zone as one value, so that would add extra step. See if something like this works for you.

your base search | eval description=if(description="network" OR description="zone","network_zone",description) 
|stats values(stringValue) as stringValue by description delim="_" | nomv stringValue
| eval date=if(description="date",stringValue,null()) | eval network_zone=if(description="network_zone",stringValue,null()) | ...any other combination...

Give this a try as well.

your base search | eval description=if(description="network" OR description="zone","network_zone",description) 
| stats values(stringValue) as stringValue by description delim="_" 
| nomv stringValue | eval temp=1 
| xyseries temp description stringValue | fields - temp
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

  Ready to master Kubernetes and cloud monitoring like the pros?Join Splunk’s Growth Engineering team for an ...

Wrapping Up Cybersecurity Awareness Month

October might be wrapping up, but for Splunk Education, cybersecurity awareness never goes out of season. ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...