Splunk Search

Is it possible to do an in-line conditional field extraction?

SplunkDash
Motivator

Hello,

Is it possible to do conditional In Line field extraction in SPLUNK for the following sample data:

Sample Data (3 Events)

tR3225256009BMFTH77770977DF74S58628201804533FGRT

fR6225256009BMFFT77779977TG76S58628201804633TSRD

gR1225256004BMGHL7090997YJK66S58628201804833EDAR

 

I have done:

(^)(?i)(?<DeprtCode>.{1})(?i)(?<mode_no>.{2})(?i)(?<StudentId>.{9})(?i)(?<BuildingCode>.{5})(?i)(?<Code>.{2})(?i)

Help Needed to Extract Field under following conditions:

If from character # 20-25 (6 Characters) are all Numerics then extract those 6 characters as Account_no, if those 6 characters are not all Numerics (like sample event 3) then extract all characters from 20-46 as no_Account

Is it possible? Any recommendations will be highly appreciated. Thank you!

 

Labels (1)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

As I always say, as long as it is mathematical, everything is possible.

 

| rex "^.{19}(?<Account_no>\d{6})"
| rex "^.{19}(?<no_Account>.+)"
| eval no_Account = if(isnull(Account_no), no_Account, null())

 

Account_no_rawno_Account
770977tR3225256009BMFTH77770977DF74S58628201804533FGRT 
779977fR6225256009BMFFT77779977TG76S58628201804633TSRD 
 gR1225256004BMGHL7090997YJK66S58628201804833EDAR90997YJK66S58628201804833EDAR

View solution in original post

Tags (1)

yuanliu
SplunkTrust
SplunkTrust

As I always say, as long as it is mathematical, everything is possible.

 

| rex "^.{19}(?<Account_no>\d{6})"
| rex "^.{19}(?<no_Account>.+)"
| eval no_Account = if(isnull(Account_no), no_Account, null())

 

Account_no_rawno_Account
770977tR3225256009BMFTH77770977DF74S58628201804533FGRT 
779977fR6225256009BMFFT77779977TG76S58628201804633TSRD 
 gR1225256004BMGHL7090997YJK66S58628201804833EDAR90997YJK66S58628201804833EDAR
Tags (1)

SplunkDash
Motivator

Hello @yuanliu 

Thank you so much for your quick response. Are there any ways with your mathematical magic, we can incorporate that extraction into my:

(^)(?i)(?<DeprtCode>.{1})(?i)(?<mode_no>.{2})(?i)(?<StudentId>.{9})(?i)(?<BuildingCode>.{5})(?i)(?<Code>.{2})(?i)

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Not sure what you mean by incorporate.  If you want the two extra field Account_no and No_Acccount, simply add the search to your search.  Here's an alternative method:

 

| rex "(^)(?i)(?<DeprtCode>.{1})(?i)(?<mode_no>.{2})(?i)(?<StudentId>.{9})(?i)(?<BuildingCode>.{5})(?i)(?<Code>.{2})(?i)"
| rex "^.{19}(?<Account_no>\d{6})"
| eval no_Account = if(isnull(Account_no), replace(_raw, ".{19}", ""), null())

 

Either way, you get

Account_noBuildingCodeCodeDeprtCodeStudentIdmode_nono_Account
770977BMFTH77t225256009R3 
779977BMFFT77f225256009R6 
 BMGHL70g225256004R1804833EDAR

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Given that you have no anchor text (alphabetic or not), you don't need "(?i)"

| rex "^(?<DeprtCode>.)(?<mode_no>..)(?<StudentId>.{9})(?<BuildingCode>.{5})(?<Code>..)(?<Account_no>\d{6})"
| rex "^(?<DeprtCode>.)(?<mode_no>..)(?<StudentId>.{9})(?<BuildingCode>.{5})(?<Code>..)(?<no_Account>.+)"
| eval no_Account = if(isnull(Account_no), no_Account, null())

SplunkDash
Motivator

@ITWhisperer 

Thank you so much for your quick response. How I would incorporate this code into SPLUNK IN-Line extraction code?

0 Karma
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

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, ...