<?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 can I create a &amp;quot;null&amp;quot; or &amp;quot;blank&amp;quot; response in a field while converting strings into a new string value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349571#M103482</link>
    <description>&lt;P&gt;@jh007 - oh, I hate those.  Sometimes you have to escape them once, giving you two slashes, and sometimes you have to escape them twice, giving you four slashes for a single one.  (And what's after them seems to matter sometimes.  Gak!)  Unfortunately, it depends on exactly where you are putting in the &lt;CODE&gt;rex&lt;/CODE&gt; - inline, in a panel, inside a map command, or in a .conf,  so I always have to play with it a bit to be certain.  &lt;/P&gt;

&lt;P&gt;Start with four slashes and if that doesn't work, cut  down to 2.  &lt;/P&gt;

&lt;P&gt;If it's in a plain search, then use &lt;CODE&gt;makeresults&lt;/CODE&gt; to create a simple example of what you are trying to UNDO, and then you can test a simple &lt;CODE&gt;rex&lt;/CODE&gt; against it  until it works, and repeat whatever worked across the full mask.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Sep 2017 00:22:03 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-09-19T00:22:03Z</dc:date>
    <item>
      <title>How can I create a "null" or "blank" response in a field while converting strings into a new string value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349567#M103478</link>
      <description>&lt;P&gt;I am not sure how to approach what I am attempting to do.  In short, I have a field that contains some specific strings that I intend to convert into a new string value inside a new field.  For all the other strings in the first field that &lt;STRONG&gt;do not match&lt;/STRONG&gt;, I want to provide a null or "blank" response in the new field.  &lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;original field values // New field value&lt;BR /&gt;
planetrainsautomobiles // modes of transportation&lt;BR /&gt;
applesPeachesblueberries // types of fruit&lt;BR /&gt;
random garbage I don't want // [blank] &lt;/P&gt;

&lt;P&gt;I know if I use the eval command in conjunction with replace I can change any string of text to what I want.  What I can't figure out is how to "null" all the garbage I don't want to show in the new field when I display it in the table. &lt;/P&gt;

&lt;P&gt;Any help would be greatly appreciated.   &lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 19:18:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349567#M103478</guid>
      <dc:creator>jh007</dc:creator>
      <dc:date>2017-09-18T19:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a "null" or "blank" response in a field while converting strings into a new string value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349568#M103479</link>
      <description>&lt;P&gt;If I understand correctly, you want something like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval NewFieldValue=case(OriginalFieldValue="planetrainsautomobiles", "modes of transportation", OriginalFieldValue="applesPeachesblueberries", "types of fruit", 1==1, "") | table OriginalFieldValue NewFieldValue
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2017 19:40:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349568#M103479</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-09-18T19:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a "null" or "blank" response in a field while converting strings into a new string value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349569#M103480</link>
      <description>&lt;P&gt;It takes just two steps.  Note that you don't have to pull the entire word, just enough to identify it, so you don't have to worry about plural or singular.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex field=origfield "(?i)(?&amp;lt;newfield&amp;gt;plane|train|automobile|apple|peach|blueberr)" max_match=0
 | eval newfield=coalesce(mvdedup(lower(newfield)),"")
 | rex field=newfield mode=sed "s/plane|train|automobile/mode of transportation/g s/apple|peach|blueberr/types of fruit/g"  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Here's where it can get fun.  &lt;/P&gt;

&lt;P&gt;Given a csv file in this format &lt;CODE&gt;| table myvalue myreplacement&lt;/CODE&gt;, this code will build the first and second rexes&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval mydata="plane,modes of transportation!!!!peach unicorn,modes of transportation!!!!train,modes of transportation!!!!automobile,modes of transportation!!!!horseless carriage,modes of transportation!!!!apple,types of fruit!!!!peach,types of fruit!!!!blueberr,types of fruit!!!!goji berr,types of fruit"
| makemv delim="!!!!" mydata 
| mvexpand mydata 
| makemv delim="," mydata
| eval myvalue=mvindex(mydata,0)
| eval myreplacement=mvindex(mydata,1)
| fields - mydata
| rename COMMENT as "the above just enters test data."


| rename COMMENT as "build the first rex with the same test data"
| rename COMMENT as "sort descending so that shorter versions of same characters are last"
| table myvalue
| sort 0 - myvalue
| rename COMMENT as "hide spaces so we can restore them later"
| rex field=myvalue mode=sed "s/ /!!!!/g"
| rename COMMENT as "format the return value and then restore the spaces"
| format "(?i)(?&amp;lt;newfield&amp;gt;" "" "" "" "|" ")"
| rex field=search mode=sed "s/myvalue=|[ \"]//g s/^\(/\"(/g s/\)$/)\"/g s/!!!!/ /g"


| rename COMMENT as "build the second rex with the same test data"
| rename COMMENT as "sort descending so that shorter versions of same characters are last"
| table myvalue myreplacement
| sort 0 - myvalue
| stats list(myvalue) as myvalue by myreplacement
| eval YYYYYYYY=mvjoin(myvalue,"|")
| rename myreplacement as ZZZZZZZZ
| table YYYYYYYY ZZZZZZZZ 
| format "" "" "" "" "" ""
| rex field=search mode=sed "s/YYYYYYYY=/s\//g s/\/\"/\//g s/\"  ZZZZZZZZ=\"/\//g s/\"/\/g /g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So the final code looks like this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex field=origfield [| inputcsv mychange.csv 
     | rename COMMENT as "sort descending so that shorter versions of same characters are last" 
     | table myvalue 
     | sort 0 - myvalue 
     | rename COMMENT as "hide spaces so we can restore them later" 
     | rex field=myvalue mode=sed "s/ /!!!!/g" 
     | rename COMMENT as "format the return value and re them later" 
     | format "(?i)(?&amp;lt;newfield&amp;gt;" "" "" "" "|" ")" 
     | rex field=search mode=sed "s/myvalue=|[ \"]//g s/^\(/\"(/g s/\)$/)\"/g s/!!!!/ /g"]  max_match=0
 | eval newfield=coalesce(mvdedup(lower(newfield)),"")
 | rex field=newfield mode=sed [| inputcsv mychange.csv 
     | rename COMMENT as "sort descending so that shorter versions of same characters are last" 
     | table myvalue myreplacement 
     | sort 0 - myvalue 
     | stats list(myvalue) as myvalue by myreplacement 
     | eval YYYYYYYY=mvjoin(myvalue,"|") 
     | rename myreplacement as ZZZZZZZZ 
     | table YYYYYYYY ZZZZZZZZ 
     | format "" "" "" "" "" "" 
     | rex field=search mode=sed "s/YYYYYYYY=/s\//g s/\/\"/\//g s/\"  ZZZZZZZZ=\"/\//g s/\"/\/g /g" ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2017 19:50:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349569#M103480</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-18T19:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a "null" or "blank" response in a field while converting strings into a new string value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349570#M103481</link>
      <description>&lt;P&gt;So the command syntax seems to work, but I am running into an issue with handling backslashes in my rex statements. Here's my example:&lt;/P&gt;

&lt;P&gt;SAM_ALIASDOMAINS\Builtin\Aliases\00000220C\C:\Windows\System32\lsass.exe ...  &lt;/P&gt;

&lt;P&gt;How do I handle these?   &lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 21:01:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349570#M103481</guid>
      <dc:creator>jh007</dc:creator>
      <dc:date>2017-09-18T21:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a "null" or "blank" response in a field while converting strings into a new string value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349571#M103482</link>
      <description>&lt;P&gt;@jh007 - oh, I hate those.  Sometimes you have to escape them once, giving you two slashes, and sometimes you have to escape them twice, giving you four slashes for a single one.  (And what's after them seems to matter sometimes.  Gak!)  Unfortunately, it depends on exactly where you are putting in the &lt;CODE&gt;rex&lt;/CODE&gt; - inline, in a panel, inside a map command, or in a .conf,  so I always have to play with it a bit to be certain.  &lt;/P&gt;

&lt;P&gt;Start with four slashes and if that doesn't work, cut  down to 2.  &lt;/P&gt;

&lt;P&gt;If it's in a plain search, then use &lt;CODE&gt;makeresults&lt;/CODE&gt; to create a simple example of what you are trying to UNDO, and then you can test a simple &lt;CODE&gt;rex&lt;/CODE&gt; against it  until it works, and repeat whatever worked across the full mask.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2017 00:22:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349571#M103482</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-19T00:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a "null" or "blank" response in a field while converting strings into a new string value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349572#M103483</link>
      <description>&lt;P&gt;It took 3 slashes oddly enough on both the rex and rex sed statements. &lt;/P&gt;

&lt;P&gt;Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2017 12:36:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349572#M103483</guid>
      <dc:creator>jh007</dc:creator>
      <dc:date>2017-09-19T12:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a "null" or "blank" response in a field while converting strings into a new string value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349573#M103484</link>
      <description>&lt;P&gt;@jh007 - see why I hate those?  Glad you got it figured out.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2017 14:26:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-quot-null-quot-or-quot-blank-quot-response-in/m-p/349573#M103484</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-19T14:26:19Z</dc:date>
    </item>
  </channel>
</rss>

