Splunk Enterprise

custom text to the results

selvam_sekar
Path Finder

Hi,

from the logs, i have extracted the below data(table1). I would like to add another column as in Table2 with custom keyword if filename begins xyz then "Core".

Please could you suggest what splunk query or logic we could apply?

Splunk Query:

base search | rex field User | rex field Folder | rex filed File
| table User  Folder File

Table1: 

User Folder File
ABC first xyz07122023

 

Table 2: Required Output

User Folder File Consumer
ABC first xyz07122023 Core
Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Use the eval command to add a field ("column").  The match function will compare a field to a string/regular expression.

base search 
| rex field User | rex field Folder | rex field File
| eval Consumer = if(match(File, "^xyz"), "Core", "")
| table User Folder File Consumer

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Use the eval command to add a field ("column").  The match function will compare a field to a string/regular expression.

base search 
| rex field User | rex field Folder | rex field File
| eval Consumer = if(match(File, "^xyz"), "Core", "")
| table User Folder File Consumer

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

selvam_sekar
Path Finder

Thanks, it worked as expected.

If we have 3 or multiple matches, do we required to write individual eval as mentioned below?

for example,

File Consumer
XYZ_*Core
ABC_*Core
MNP_*Non-Core
RSTNon-Core

 

SPL: 

 

base search 
| rex field User | rex field Folder | rex field File
| eval Consumer = if(match(File, "^xyz"), "Core", "")
| eval Consumer = if(match(File,"^ABC"),"Core","")
| eval Consumer = if(match(File,"^MNP"),"Non-Core","")
| table File Consumer

 

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

That won't work as expected.  If File is "XYZ_*" then Consumer will be set to "" because of the last eval statement.  For instances like this, use the case function.

 

base search 
| rex field User | rex field Folder | rex field File
| eval Consumer = case(match(File, "^xyz"), "Core",
                       match(File,"^ABC"),"Core",
                       match(File,"^MNP"),"Non-Core",
                       1==1,"Others")
| table File Consumer

 

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

selvam_sekar
Path Finder

Thanks a lot

0 Karma

selvam_sekar
Path Finder

Excellent! Many thanks.

is it possible if we make the non-matching of  the below files to map "Others".

for example,

other than file name starts with xyz, ABC, MNP  as Others.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

See my updated reply.  The last clause of this case function handles non-matches.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...