<?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 Escaping characters in an event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14754#M1640</link>
    <description>&lt;P&gt;I have a dataset that is going into Splunk where an event is a timestamp followed by a list of key value pairs where the value is set in quotes, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010-01-01 00:00 key="value" key2="value2" key3="value3"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some of the values however, may contain the "-character. Is there any way for me to escape these to ensure the entire field value is extracted by Splunk, and make sure Splunk only finds one field - text - in the following input, and not two fields - text and status:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010-01-01 00:00 text="This text contains status="200" and it confuses Splunk"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Jun 2010 02:53:49 GMT</pubDate>
    <dc:creator>jwestberg</dc:creator>
    <dc:date>2010-06-03T02:53:49Z</dc:date>
    <item>
      <title>Escaping characters in an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14754#M1640</link>
      <description>&lt;P&gt;I have a dataset that is going into Splunk where an event is a timestamp followed by a list of key value pairs where the value is set in quotes, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010-01-01 00:00 key="value" key2="value2" key3="value3"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some of the values however, may contain the "-character. Is there any way for me to escape these to ensure the entire field value is extracted by Splunk, and make sure Splunk only finds one field - text - in the following input, and not two fields - text and status:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010-01-01 00:00 text="This text contains status="200" and it confuses Splunk"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Jun 2010 02:53:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14754#M1640</guid>
      <dc:creator>jwestberg</dc:creator>
      <dc:date>2010-06-03T02:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Escaping characters in an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14755#M1641</link>
      <description>&lt;P&gt;Is this log format that you control?  In other words, are you asking about best practices for writing out log messages in a format that splunk will handle natively, or is this just an example of what you have to deal with that somebody else is writing out?&lt;/P&gt;

&lt;P&gt;I'm not sure you can &lt;EM&gt;escape&lt;/EM&gt; the quote, but I know that sometimes splunk handles this better:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010-01-01 00:00 key="value", key2="value2", key3="value3"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you have a comma between your events like this, then you may be able to use splunk's delimited field extractions.  (I'm borrowing this from Splunk's built-in &lt;CODE&gt;stash&lt;/CODE&gt; sourcetype which is used for summary indexing events which are automatically formatted to look like the key/value message shown above.)  The key to this approach is the &lt;CODE&gt;DELMIS = ",", "="&lt;/CODE&gt; entry.&lt;/P&gt;

&lt;P&gt;Sample &lt;CODE&gt;props.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my_source_type]
KV_MODE = none
REPORT-my_fields = kv_comma_sep
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample &lt;CODE&gt;transforms.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[kv_comma_sep]
DELIMS       = ",", "="
CAN_OPTIMIZE = false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;You may also find Splunk's &lt;A href="http://www.splunk.com/wiki/Apps%3aCommon_Information_Model" rel="nofollow"&gt;Common Information Model&lt;/A&gt; wiki page helpful.&lt;/LI&gt;
&lt;LI&gt;To handle these at search time, you will probably need to use a custom field extraction.  See &lt;A href="http://www.splunk.com/base/Documentation/latest/Knowledge/Addfieldsatsearchtime" rel="nofollow"&gt;Overview of search-time field extraction&lt;/A&gt; in the docs.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 03 Jun 2010 04:08:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14755#M1641</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-06-03T04:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Escaping characters in an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14756#M1642</link>
      <description>&lt;P&gt;Yes, I do have control over the log format, in that it is a scripted input. Sadly, adding a comma in between fields as per your suggestion did not alleviate the problem.&lt;/P&gt;

&lt;P&gt;While I in theory could replace all "-characters in the dataset with “ or similar, that could lead to other problems down the line with copy/pasting search results.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2010 00:50:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14756#M1642</guid>
      <dc:creator>jwestberg</dc:creator>
      <dc:date>2010-06-10T00:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Escaping characters in an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14757#M1643</link>
      <description>&lt;P&gt;Okay, if you have control over the output format, and you have relatively arbitrary field values (e.g., they might actually contain things like &lt;CODE&gt;name=word&lt;/CODE&gt; in the middle of a field value), I would go to a multi-line input format, and set up a unique delimiter between events, e.g., your script would output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010-06-10 12:34:56.789
field1=value value value name=something and stuff
fieldnameX=blah asdfasdf something else something something "this" name="this"
fieldthree=5
----%%%----
2010-06-10 12:34:56.890
myfield=value
another=ggggg
----%%%----
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;etc. And your props for that would be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SHOULD_LINEMERGE = false
# that's right, *false*
LINE_BREAKER = ([\r\n]*----%%%---[\r\n]*)(?=\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})
REPORT-x = y
KV_MODE = none
TIME_FORMAT = %Y-%m-%d %H:%M:%S.%3N
TIME_PREFIX = ^
MAX_TIMESTAMP_LOOKAHEAD = 25
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[y]
REGEX = (\w+)=([^\r\n]*)
FORMAT = $1::$2
MV_ADD = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course, this only works if your values don't contain newlines or CR. And in general, this is just a version of choosing a delimiter character that doesn't occur in the data, in this case a newline. If you &lt;EM&gt;have&lt;/EM&gt; to, you can use a character &lt;EM&gt;sequence&lt;/EM&gt; between fields provided it doesn't occur in the string, and modify the field extraction REGEX to something like &lt;CODE&gt;(?s)(\w+)=([\S\s]+)(?!\n+++(?:\n|$))&lt;/CODE&gt;, if you have to divide fields using &lt;CODE&gt;+++&lt;/CODE&gt; on a line by itself. That means you'll need a delimiter sequence between events, and a different one between KV pairs.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2010 21:17:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14757#M1643</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-06-11T21:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Escaping characters in an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14758#M1644</link>
      <description>&lt;P&gt;Hmm.  I've updated my answer and added some sample config entries.  I think this will work better for you.  Basically we are disabling splunk default &lt;CODE&gt;key=value&lt;/CODE&gt; expansion and forcing it to use a delimiter-based extraction pattern which takes commas into consideration.  I think this will work for you.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2010 21:31:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14758#M1644</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-06-11T21:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Escaping characters in an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14759#M1645</link>
      <description>&lt;P&gt;11.111.11.11 - - [26/Oct/2013:17:04:56 -0700] "POST /abc/abcd/xx HTTP/1.1" 200 885&lt;/P&gt;

&lt;P&gt;How can we transform above line ... &lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2013 04:57:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14759#M1645</guid>
      <dc:creator>ravinderbisht</dc:creator>
      <dc:date>2013-10-29T04:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Escaping characters in an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14760#M1646</link>
      <description>&lt;P&gt;[]  and "" are screwing the things...&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2013 04:58:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Escaping-characters-in-an-event/m-p/14760#M1646</guid>
      <dc:creator>ravinderbisht</dc:creator>
      <dc:date>2013-10-29T04:58:24Z</dc:date>
    </item>
  </channel>
</rss>

