Splunk Search

How do you extract data between double quotes?

Deepz2612
Explorer

I have logs as below.I would want to extract the data within the quotes

 **message**: "vin":"ABCDEFTGH","Type":"Obs-AVE","color":"ABSOLUTE BLACK"

Where message is a field.

I want the value as:

VIN

ABCDEFTGH

Tags (2)
0 Karma
1 Solution

renjith_nair
Legend

@Deepz2612 ,

Try

"Your current search"  |rex field=_raw max_match=0 "\"(?<KEY>.+?)\":\"(?<VALUE>.+?)\""
|eval x=mvzip(KEY,VALUE)|table x|mvexpand x
|rex field=x "(?<KEY>.+),(?<VALUE>.+)"|fields - x|transpose 0 header_field=KEY|fields - column

This will result in

vin         Type        color
ABCDEFTGH   Obs-AVE     ABSOLUTE BLACK
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

vnravikumar
Champion

Try this

| makeresults 
 | eval test ="**message**: \"vin\":\"ABCDEFTGH\",\"Type\":\"Obs-AVE\",\"color\":\"ABSOLUTE BLACK\"" 
 | rex field=test "\"vin\":\"(?<vin>.*)\",\"Type\":\"(?<Type>.*)\",\"color\":\"(?<color>.*)\"" 
 | table vin, Type, color
0 Karma

renjith_nair
Legend

@Deepz2612 ,

Try

"Your current search"  |rex field=_raw max_match=0 "\"(?<KEY>.+?)\":\"(?<VALUE>.+?)\""
|eval x=mvzip(KEY,VALUE)|table x|mvexpand x
|rex field=x "(?<KEY>.+),(?<VALUE>.+)"|fields - x|transpose 0 header_field=KEY|fields - column

This will result in

vin         Type        color
ABCDEFTGH   Obs-AVE     ABSOLUTE BLACK
---
What goes around comes around. If it helps, hit it with Karma 🙂

Deepz2612
Explorer

Hi,

The question here is how do i extract the data within the quotes.
message: "vin":"ABCDEFTGH","Type":"Obs-AVE","color":"ABSOLUTE BLACK"
message: "vin":"EFGHTYB","Type":"Obs-ABE","color":"BLACK"

Like in the logs above ,I would want to extract the values as between the quotes as a field value.
eg: whatever data follows after the word "vin":" and ended with ", should be extracted as one field.
ABCDEFTGH

0 Karma

harsmarvania57
Ultra Champion

Have you tried the query provided by me and @renjith.nair ? It is extracting ABCDEFTGH in field vin, Obs-AVE in field Type and ABSOLUTE BLACK in field color

0 Karma

Deepz2612
Explorer

It did work but not in the way i expected.
I just wanted to have a reqular expression to extract the data that is present within the quotes and a colon.

rex field = message *********************

message: "vin":"EFGHTYB"

Here the data EFGHTYB is between :" and "

0 Karma

renjith_nair
Legend

@Deepz2612 ,

If you just want VIN, try this

rex field=your_message_field "vin":\"(?<VIN>\w+)\""
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

Deepz2612
Explorer

Cool!! Thanks for your help

0 Karma

harsmarvania57
Ultra Champion

Hi @Deepz2612,

I am not able to find an easy way to do this but you can try below query.

<yourBaseSearch>
| rex "\"(?:(?<a>\w+))\"\:\"(?<b>(?:.)*?)\"" max_match=0
| eval c = mvzip(a,b)
| mvexpand c
| eval d=mvindex(split(c,","),0), e=mvindex(split(c,","),1)
| eval {d}=e
| stats values(color) AS color, values(vin) AS vin, values(Type) AS Type by _time

Here is run anywhere search based on sample data

| makeresults | eval _raw="message: \"vin\":\"ABCDEFTGH\",\"Type\":\"Obs-AVE\",\"color\":\"ABSOLUTE BLACK\""
| rex "\"(?:(?<a>\w+))\"\:\"(?<b>(?:.)*?)\"" max_match=0
| eval c = mvzip(a,b)
| mvexpand c
| eval d=mvindex(split(c,","),0), e=mvindex(split(c,","),1)
| eval {d}=e
| stats values(color) AS color, values(vin) AS vin, values(Type) AS Type by _time

EDIT : REGEX Updated.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...