Splunk Search

How to extract the all the field using rex?

karthi2809
Builder

How to extract success and fatal into one field and also extract two Fields after FATAL

2018-06-18 02:06:34,606|261529301994221|MA_SELECT|785M91236|602304234|001|WGS20||||EMAIL|SPALACIOS810@GMAIL.COM|LEVEL2|||SUCCESS|| 
2018-06-18 02:06:34,294|7961529301994286|MA_SELECT|AN72688470000|202465241|001|NASCO||||EMAIL|SANGELI@OUTDRS.NET|LEVEL2|||
FATAL|E000057P|Member not found 
0 Karma
1 Solution

FrankVl
Ultra Champion

Shortcut approach to extract into result field:

| rex "\|(?<result>SUCCESS|FATAL)\|"

This is a shortcut since it assumes there are no other part of the event that could match this SUCCESS or FATAL string.

A safer approach would be to create a regex that extracts the SUCCESS/FATAL value from the expected location in the message:

| rex "(?:[^\|]*\|){15}(?<result>SUCCESS|FATAL)"

https://regex101.com/r/FvClhk/1

An other option is to configure delimiter based field extraction.

props.conf:

REPORT-extractfields = extractfields

transforms.conf

[extractfields]
DELIMS = "|"
FIELDS = field1, field2, field3

Note: replace the field1 etc. with your own list of comma separated field names.

View solution in original post

rlait_splunk
Splunk Employee
Splunk Employee

If it's just FATAL or SUCCESS, you could try:

(?<status>FATAL|SUCCESS)

FrankVl
Ultra Champion

Shortcut approach to extract into result field:

| rex "\|(?<result>SUCCESS|FATAL)\|"

This is a shortcut since it assumes there are no other part of the event that could match this SUCCESS or FATAL string.

A safer approach would be to create a regex that extracts the SUCCESS/FATAL value from the expected location in the message:

| rex "(?:[^\|]*\|){15}(?<result>SUCCESS|FATAL)"

https://regex101.com/r/FvClhk/1

An other option is to configure delimiter based field extraction.

props.conf:

REPORT-extractfields = extractfields

transforms.conf

[extractfields]
DELIMS = "|"
FIELDS = field1, field2, field3

Note: replace the field1 etc. with your own list of comma separated field names.

karthi2809
Builder

I need to extract two fields after FATAL

0 Karma

493669
Super Champion

@karthi2809, try this extended version to extract remaining fields:

 |rex field=data "\|(?<result>SUCCESS|FATAL)\|(?<number>\w+)?\|(?<status>[a-zA-Z ]+)?"

karthi2809
Builder

Thank you so much

0 Karma

Anam
Community Manager
Community Manager

Hi @karthi2809

My name is Anam and I am the Community Content Specialist for Splunk Answers. Please go ahead and accept the answer that worked for you. If it is a comment, let me know and I can convert it to an answer and accept it.

Thanks

0 Karma

mayurr98
Super Champion

can you put the sample events in 101010 sample code format as I am not able to understand it

0 Karma

karthi2809
Builder

101010|101010|101010|101010|101010|101010|101010||||101010|101010|101010|||FATAL|E000110|file not found
101010|101010|101010|101010|101010|101010|101010||||101010| 101010 |101010|||SUCCESS||
101010|101010|101010|101010|101010|101010|101010|||101010|101010| 101010 |101010|||FATAL|E10021|file not found

0 Karma

FrankVl
Ultra Champion

he meant using the 101010 button in the editor, to mark the sample as code, that prevents special characters from dissapearing etc.

But take a look at my answer below and see if that works.

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...