Splunk Search

How to extract field between double quotes using rex?

MaratD
Explorer

Hi all,

I have the following events

source_host=lioness1 source_host_description="This is the main server"

source_host=lion source_host_description="This is SQL server"

 

I need to extract the description, which is all the text between double quotes and assign it to the field description. Would you please help?

 

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

At search time, use this rex command:

| rex "\\\"(?<description>[^\\\"]+)"

The same regex should work at index time, just without the escape characters.

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

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

At search time, use this rex command:

| rex "\\\"(?<description>[^\\\"]+)"

The same regex should work at index time, just without the escape characters.

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

sureshkumaar
Path Finder

Hi @richgalloway - How about in this case?

Where we have multiple lines within double quotes and to be updated in the different field names according to the name we have.

All values has to be in different field names separately which is within double quotes

"17449551"
"pmqcd1p3"
"SAP for Oracle"
"PMQ"
"N/A"
"default"
"(Logcommand line)"
Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

As the last reply on this thread stated, this question has an accepted answer so it's unlikely to draw more viewers.  Please post a new question.

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

splunkreal
Motivator

Hi,

looks like we need to espace double quotes, do you advice this log format:

key=value instead of key="value" ? Thanks.

 

* If this helps, please upvote or accept solution if it solved *
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This question has an accepted answer so it's unlikely to draw more viewers.  Please post a new question.

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

MaratD
Explorer

thanks, but this could match any string between "". My bad I didn't make it clear enough. I can have other values between double quotes and I want to make sure that this regex only matches the description. so I did something like this 

rex "description=\\\"(?<description>[^\\\"]+)"

But it didn't work

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Your regex should work, assuming there is no hidden white space in the data.  Is source_host_description an extracted field?  If so, you can use the original regex against that one field.

| rex field=source_host_description "\\\"(?<description>[^\\\"]+)"

 If that doesn't work then it might help if you shared a full (sanitized) raw event.

---
If this reply helps you, Karma would be appreciated.
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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...