<?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 do I reverse/swap characters in a string value returned from a search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219954#M64650</link>
    <description>&lt;P&gt;Don't forget to accept the answer by clicking on the Accept hyperlink below the answer.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Sep 2015 20:27:36 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2015-09-11T20:27:36Z</dc:date>
    <item>
      <title>How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219949#M64645</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;If my search returns a string value of "ABCDEF"&lt;/P&gt;

&lt;P&gt;1) How do I modify the search to reverse this value so it outputs "FEDCBA" ?&lt;/P&gt;

&lt;P&gt;2) How do I swap characters from this value so it outputs "BADCFE" ? (1st 2 characters are being swapped)&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 18:31:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219949#M64645</guid>
      <dc:creator>ajay_mk</dc:creator>
      <dc:date>2015-09-11T18:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219950#M64646</link>
      <description>&lt;P&gt;This does just the first 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=myField mode=sed "s/(.)(.)/\2\1/" | table host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Extend  the example (more &lt;CODE&gt;(.)&lt;/CODE&gt; in the first section and more &lt;CODE&gt;\#&lt;/CODE&gt; in the second section) to reverse longer strings.&lt;/P&gt;

&lt;P&gt;This byteswaps an entire string of any length (every pair):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=myField mode=sed "s/(.)(.)/\2\1/g" | table host
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2015 19:36:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219950#M64646</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-09-11T19:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219951#M64647</link>
      <description>&lt;P&gt;I would suggest one correction to add "g" flag in the end to do it for all characters. like &lt;CODE&gt;s/(.)(.)/\2\1/g&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 19:52:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219951#M64647</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-11T19:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219952#M64648</link>
      <description>&lt;P&gt;Hey thanks I just ran what you mentioned but its only swapping the first 2 characters. &lt;/P&gt;

&lt;P&gt;Value to swap = 535276&lt;BR /&gt;&lt;BR /&gt;
Swapped value &lt;STRONG&gt;35&lt;/STRONG&gt;5276    &lt;/P&gt;

&lt;P&gt;Changing the lengths doesnt seem to work?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 19:57:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219952#M64648</guid>
      <dc:creator>ajay_mk</dc:creator>
      <dc:date>2015-09-11T19:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219953#M64649</link>
      <description>&lt;P&gt;ha perfect that worked. thank you both!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 19:58:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219953#M64649</guid>
      <dc:creator>ajay_mk</dc:creator>
      <dc:date>2015-09-11T19:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219954#M64650</link>
      <description>&lt;P&gt;Don't forget to accept the answer by clicking on the Accept hyperlink below the answer.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 20:27:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219954#M64650</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-11T20:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219955#M64651</link>
      <description>&lt;P&gt;Did you add the 'g' in the end as mentioed in the comment? Try this runanywhere sample search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval myField="535276" |  rex field=myField mode=sed "s/(.)(.)/\2\1/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2015 21:43:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219955#M64651</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-11T21:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219956#M64652</link>
      <description>&lt;P&gt;yes the g worked thanks again. &lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 21:44:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219956#M64652</guid>
      <dc:creator>ajay_mk</dc:creator>
      <dc:date>2015-09-11T21:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219957#M64653</link>
      <description>&lt;P&gt;Sorry guys, but this is one of the sweetest regex ever on answers! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2015 08:58:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219957#M64653</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-09-12T08:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219958#M64654</link>
      <description>&lt;P&gt;OK @MuS, cough up some up-vote love!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 17:50:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219958#M64654</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-09-16T17:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219959#M64655</link>
      <description>&lt;P&gt;Reverse that string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1| eval forward="ABCDEF" | eval reverse=replace(forward,"(.)(.)(.)(.)(.)(.)","\6\5\4\3\2\1")| table forward reverse
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Reverse the first two characters only:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1| eval forward="ABCDEF" | eval reverse2=replace(forward,"(.)(.)","\2\1")| table forward reverse2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:00:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219959#M64655</guid>
      <dc:creator>wrangler2x</dc:creator>
      <dc:date>2015-11-06T22:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219960#M64656</link>
      <description>&lt;P&gt;Think of &lt;CODE&gt;| gentimes start=-1&lt;/CODE&gt; as your search. This just allows the demonstration of this function, but any search can replace that part. And -- of course, the &lt;CODE&gt;| eval forward="ABCDEF"&lt;/CODE&gt; is just the setup to give us a string to work with. In a real search that would be omitted, and &lt;STRONG&gt;forward&lt;/STRONG&gt; could be any field with a string in it. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:02:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219960#M64656</guid>
      <dc:creator>wrangler2x</dc:creator>
      <dc:date>2015-11-06T22:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219961#M64657</link>
      <description>&lt;P&gt;This solution works for a fixed length string. Is there way of performing character reversal for variable length fields apart from have multiple  regex's with different search and replacments lengths&lt;/P&gt;

&lt;P&gt;|rex field=nbr mode=sed "s/(\d).(\d).(\d).(\d).(\d).(\d).(\d).(\d).(\d).(\d)/\10\9\8\7\6\5\4\3\2\1/" &lt;BR /&gt;
| rex field=nbr mode=sed "s/(\d).(\d).(\d).(\d).(\d).(\d).(\d).(\d).(\d)/\9\8\7\6\5\4\3\2\1/" &lt;BR /&gt;
| rex field=nbr mode=sed "s/(\d).(\d).(\d).(\d).(\d).(\d).(\d).(\d)/\8\7\6\5\4\3\2\1/" &lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 22:52:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219961#M64657</guid>
      <dc:creator>jhuysing</dc:creator>
      <dc:date>2019-07-22T22:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reverse/swap characters in a string value returned from a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219962#M64658</link>
      <description>&lt;P&gt;Post a new question.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 13:46:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-reverse-swap-characters-in-a-string-value-returned-from/m-p/219962#M64658</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-23T13:46:56Z</dc:date>
    </item>
  </channel>
</rss>

