<?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: How to extract fields from my string logs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475453#M192563</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search&amp;gt; | rex field=_raw mode=sed "s/This is my logfile -&amp;gt;\smyfulljson\s{\s/{\"/g" | rex field=_raw mode=sed "s/\s{\svalue:/\":/g" | rex field=_raw mode=sed "s/\s}\s/,\"/g" | spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Feb 2020 19:48:24 GMT</pubDate>
    <dc:creator>manjunathmeti</dc:creator>
    <dc:date>2020-02-22T19:48:24Z</dc:date>
    <item>
      <title>How to extract fields from my string logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475451#M192561</link>
      <description>&lt;P&gt;I have something like below logged in as a message. &lt;BR /&gt;
How can i replace "This is my logfile ** -&amp;gt;" with empty and then how to extract name, startdate, dept, enddate, status, id and get the values.&lt;BR /&gt;
This is my logfile ** -&amp;gt;&lt;BR /&gt;
myfulljson {&lt;BR /&gt;
  name {&lt;BR /&gt;
    value: "Test"&lt;BR /&gt;
  }&lt;BR /&gt;
  startdate {&lt;BR /&gt;
    value: "2020-02-21"&lt;BR /&gt;
  }&lt;BR /&gt;
  dept {&lt;BR /&gt;
    value: 110&lt;BR /&gt;
  }&lt;BR /&gt;
  enddate {&lt;BR /&gt;
    value: "20200220"&lt;BR /&gt;
  }&lt;BR /&gt;
  status {&lt;BR /&gt;
    value: "finish"&lt;BR /&gt;
  }&lt;BR /&gt;
  id {&lt;BR /&gt;
    value: "1234"&lt;BR /&gt;
  }&lt;BR /&gt;
}&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 18:18:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475451#M192561</guid>
      <dc:creator>kotig</dc:creator>
      <dc:date>2020-02-22T18:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my string logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475452#M192562</link>
      <description>&lt;P&gt;Just a guess.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval _raw = replace ( _raw, "This is my logfile -&amp;gt;", "") | spath | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Feb 2020 18:33:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475452#M192562</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-02-22T18:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my string logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475453#M192563</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search&amp;gt; | rex field=_raw mode=sed "s/This is my logfile -&amp;gt;\smyfulljson\s{\s/{\"/g" | rex field=_raw mode=sed "s/\s{\svalue:/\":/g" | rex field=_raw mode=sed "s/\s}\s/,\"/g" | spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Feb 2020 19:48:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475453#M192563</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-02-22T19:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my string logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475454#M192564</link>
      <description>&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="This is my logfile -&amp;gt;
myfulljson {
name {
value: \"Test\"
}
startdate {
value: \"2020-02-21\"
}
dept {
value: 110
}
enddate {
value: \"20200220\"
}
status {
value: \"finish\"
}
id {
value: \"1234\"
}
}" 
| rex max_match=0 "(?m)(?&amp;lt;fieldname&amp;gt;[a-z]+)\s{\s*value:\s(?&amp;lt;fieldvalue&amp;gt;\S+)" 
| eval fieldvalue=trim(fieldvalue,"\"\"") 
| eval _raw=mvzip(fieldname,fieldvalue,"=") 
| kv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is not valid JSON. &lt;CODE&gt;spath&lt;/CODE&gt; is not useful. but, we can create valid JSON. As @manjunathmeti did.&lt;BR /&gt;
I use &lt;CODE&gt;rex&lt;/CODE&gt; to extract fields and values.  and, rename to &lt;EM&gt;_raw&lt;/EM&gt; .&lt;BR /&gt;
so &lt;CODE&gt;kv&lt;/CODE&gt; is useful.  AS @woodcock did.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 21:56:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475454#M192564</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-02-22T21:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my string logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475455#M192565</link>
      <description>&lt;P&gt;Yea tried this one unfortunately i am getting empty result. Thank you for help..&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 03:52:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475455#M192565</guid>
      <dc:creator>kotig</dc:creator>
      <dc:date>2020-02-23T03:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my string logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475456#M192566</link>
      <description>&lt;P&gt;Your trash log is not even CLOSE to valid JSON.&lt;BR /&gt;
I used this tool to figure out how to fix it:&lt;BR /&gt;
&lt;A href="https://jsonlint.com/"&gt;https://jsonlint.com/&lt;/A&gt;&lt;BR /&gt;
Then I ended up with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="This is my logfile -&amp;gt;
 myfulljson {
 name {
 value: \"Test\"
     }
 startdate {
 value: \"2020-02-21\"
     }
 dept {
 value: 110
 }
 enddate {
 value: \"20200220\"
     }
 status {
 value: \"finish\"
     }
 id {
 value: \"1234\"
     }
 }"
| rename COMMENT AS "Strip off the header garbage"
| rex mode=sed "s/^This is my logfile\s*\-&amp;gt;[\r\n\s]*myfulljson[\r\n\s]*//"
| rename COMMENT AS "Transform the non-JSON to mostly-compliant-JSON"
| rex mode=sed "s/(\w+)([\r\n\s]*\{)/\"\1\":\2/g s/value: /\"value\": /g s/\}([\r\n\s]*\")/},\1/g"
| rename COMMENT AS "OKish JSON is now parseable with 'KV_MODE=json'"
| kv
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Feb 2020 23:39:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475456#M192566</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-02-23T23:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my string logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475457#M192567</link>
      <description>&lt;P&gt;To do this properly, you should transform this garbage into fully-compliant JSON (that means removing ALL whitesapce) &lt;EM&gt;BEFORE&lt;/EM&gt; it is indexed.  This will save you license and allow &lt;CODE&gt;KV_MODE=json&lt;/CODE&gt; to "just work".&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 01:41:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-string-logs/m-p/475457#M192567</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-02-24T01:41:11Z</dc:date>
    </item>
  </channel>
</rss>

