Splunk Search

rex pattern to create a field

iamtrying
New Member

Hi,
I have this string in the log.

439 XObk5g6CUI62-gr3UIKfXAAAAAs 1@43465473@A

and I want to create a field out the string in the bold.

Please mind that 439 and 1@43465473@A are not constant.

Thanks for the help!

Saurabh

0 Karma

vnravikumar
Champion

Hi @iamtrying

Try this also

| makeresults 
| eval msg="439 XObk5g6CUI62-gr3UIKfXAAAAAs 1@43465473@A", result = mvindex(split(msg," "),1)
0 Karma

nabeel652
Builder

Try this

| makeresults | fields - _time | eval rawdata="439 XObk5g6CUI62-gr3UIKfXAAAAAs 1@43465473@A" | rex field=rawdata "^\d+\s(?<myField>[^\s]*)\s"

More general regex would be:

| makeresults | fields - _time | eval rawdata="439 XObk5g6CUI62-gr3UIKfXAAAAAs 1@43465473@A" | rex field=rawdata "^.*?\s(?<myField>[^\s]*)"
0 Karma

iamtrying
New Member

the whole string looks like this

I 2019-05-23 22:27:15.886Z 5960 1712 XOceMpk7Ph@Lna20eJwxXwAAAAU 1@43465473@A WPB-Log: file=/users/source/testr.cls method=testmethod ID= ok=1 ProcessedBankTxnCount=2 TxnRecord=289 NumOfProcessedTxns=1

I am using
rex field=rawdata "^\d+\s(?[^\s]*)\s" | table myField

but it does not match anything.

Am I missing anything?

0 Karma

nabeel652
Builder

You need to skip time stamp and then few other fields:

Use this

| makeresults | fields - _time | eval rawdata="I 2019-05-23 22:27:15.886Z 5960 1712 XOceMpk7Ph@Lna20eJwxXwAAAAU 1@43465473@A WPB-Log: file=/users/source/testr.cls method=testmethod ID= ok=1 ProcessedBankTxnCount=2 TxnRecord=289 NumOfProcessedTxns=1" | rex field=rawdata ".*?\s.*?\s.*?\s.*?\s.*?\s(?<myField>[^\s]*)" | table myField
0 Karma
Get Updates on the Splunk Community!

Exciting News: The AppDynamics Community Joins Splunk!

Hello Splunkers,   I’d like to introduce myself—I’m Ryan, the former AppDynamics Community Manager, and I’m ...

The All New Performance Insights for Splunk

Splunk gives you amazing tools to analyze system data and make business-critical decisions, react to issues, ...

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...