<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Extract field that might be surrounded by quotes in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462546#M130405</link>
    <description>&lt;P&gt;Hi aohls,&lt;BR /&gt;
could you share an example of your logs?&lt;BR /&gt;
Anyway, you have two choices:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;create a regex for both with and without quotes, bus often is difficult;&lt;/LI&gt;
&lt;LI&gt;create towo different extractions (e.g. operation1 and operation2) and then merge values using coalesce,&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| index=my_index
| rex "operation\=\"(?&amp;lt;operation1&amp;gt;[^\"]*)"
| rex "operation\=(?&amp;lt;operation2&amp;gt;[^,]*)"
| eval operation=coalesce(operation1,operation2)
| ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2019 14:20:19 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2019-08-27T14:20:19Z</dc:date>
    <item>
      <title>Extract field that might be surrounded by quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462544#M130403</link>
      <description>&lt;P&gt;I am working to extract a field that at times is surrounded by quotes. This means I have either; operation or "operation". I have attempted the following:&lt;BR /&gt;
Log Example:&lt;BR /&gt;
operation="status"&lt;BR /&gt;
operation=status&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;operation="?(?P&amp;lt;operation&amp;gt;"?[^\,]+),
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Doing this does is close but on the fields with quotes, the closing quote is included which I did not want. My thought is to just do two extractions with the same name which is not ideal for me. I am extracting until a comma, which is either after the end of the string or after the closing quote.&lt;/P&gt;

&lt;P&gt;Edit: I do not want to do anything at search time, I want the values to be correct for other users with limited knowledge.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:09:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462544#M130403</guid>
      <dc:creator>aohls</dc:creator>
      <dc:date>2019-08-27T14:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field that might be surrounded by quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462545#M130404</link>
      <description>&lt;P&gt;you can just try a replace after the operation is extracted&lt;BR /&gt;
|  eval operation=replace(operation,"\"","")&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:18:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462545#M130404</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-08-27T14:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field that might be surrounded by quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462546#M130405</link>
      <description>&lt;P&gt;Hi aohls,&lt;BR /&gt;
could you share an example of your logs?&lt;BR /&gt;
Anyway, you have two choices:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;create a regex for both with and without quotes, bus often is difficult;&lt;/LI&gt;
&lt;LI&gt;create towo different extractions (e.g. operation1 and operation2) and then merge values using coalesce,&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| index=my_index
| rex "operation\=\"(?&amp;lt;operation1&amp;gt;[^\"]*)"
| rex "operation\=(?&amp;lt;operation2&amp;gt;[^,]*)"
| eval operation=coalesce(operation1,operation2)
| ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:20:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462546#M130405</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-08-27T14:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field that might be surrounded by quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462547#M130406</link>
      <description>&lt;P&gt;I am hoping to accomplish this within the extraction and avoid any search time requirements. &lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:39:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462547#M130406</guid>
      <dc:creator>aohls</dc:creator>
      <dc:date>2019-08-27T14:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field that might be surrounded by quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462548#M130407</link>
      <description>&lt;P&gt;Try this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search&amp;gt; | rex "operation=(|\")(?&amp;lt;operation&amp;gt;[^(|\")]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search&amp;gt; | rex "operation=(|\")(?&amp;lt;operation&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:43:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462548#M130407</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-08-27T14:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field that might be surrounded by quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462549#M130408</link>
      <description>&lt;P&gt;Right now you have the optional closing quote inside of your capture parenthesis.  Try moving it outside with something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;operation="?(?&amp;lt;operation&amp;gt;[^\,"]+)"?,
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See the working example here:  &lt;A href="https://rubular.com/r/KvJKsg4drQl51V"&gt;https://rubular.com/r/KvJKsg4drQl51V&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:47:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462549#M130408</guid>
      <dc:creator>justinatpnnl</dc:creator>
      <dc:date>2019-08-27T14:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field that might be surrounded by quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462550#M130409</link>
      <description>&lt;P&gt;This works perfect, I had attempted something similar but I had: &lt;CODE&gt;operation="?(?&amp;lt;operation&amp;gt;[^\,]+)"?,&lt;/CODE&gt;. I was missing a quote in the expression so I was getting the closing quote in my result. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:51:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-field-that-might-be-surrounded-by-quotes/m-p/462550#M130409</guid>
      <dc:creator>aohls</dc:creator>
      <dc:date>2019-08-27T14:51:26Z</dc:date>
    </item>
  </channel>
</rss>

