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 🙂 *
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
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...