<?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 calculate the difference between two fields from different files? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184513#M53137</link>
    <description>&lt;P&gt;Feel free to upvote if this helped!&lt;/P&gt;</description>
    <pubDate>Tue, 20 Mar 2018 15:01:25 GMT</pubDate>
    <dc:creator>skoelpin</dc:creator>
    <dc:date>2018-03-20T15:01:25Z</dc:date>
    <item>
      <title>How to calculate the difference between two fields from different files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184507#M53131</link>
      <description>&lt;P&gt;I have two different files abc and abc1. Both have two fields TS1 and TS2. I just want to calculate difference between TS2 of abc1 with TS1 of ABC. I'm new here so please help me guys.  Thanx in Advance..&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2015 09:51:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184507#M53131</guid>
      <dc:creator>rahul_monty</dc:creator>
      <dc:date>2015-08-24T09:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields from different files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184508#M53132</link>
      <description>&lt;P&gt;Are they both going to the same index? If so then it would be easy, you need to use the eval command which will create a new field (Diff) which will then have the difference between TS2 and TS1&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah TS1 TS2 | eval Diff=TS2-TS1 | table Diff 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;index=blah is where you define what index you want to search in &lt;BR /&gt;
TS1 TS2 is calling those fields within index=blah for faster search performance&lt;BR /&gt;
|eval is a command in splunk which will make a new field called Diff which will store the difference between TS2 and TS1&lt;BR /&gt;
|table Diff will create a table with a column called Diff which will display the difference between TS2 and TS1&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2015 13:43:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184508#M53132</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2015-08-24T13:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields from different files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184509#M53133</link>
      <description>&lt;P&gt;Will need more information than this. How is your data stored in Splunk for these two files, What type of difference you want to check, any sample values?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2015 15:47:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184509#M53133</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-24T15:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields from different files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184510#M53134</link>
      <description>&lt;P&gt;You may try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=sth source="abc" | table TS1 | appendcols [search index=sth source="abc1" | table TS2 | rename TS2 as abc1_TS2] | eval Diff = abc1_TS2 - TS1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If these two files are unrelated, you can just use appendcols. Otherwise you should use join [common field]&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 01:07:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184510#M53134</guid>
      <dc:creator>chanmi2</dc:creator>
      <dc:date>2015-08-25T01:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields from different files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184511#M53135</link>
      <description>&lt;P&gt;It's possible that the above version works for you in this case but here's how I'd solve it(assuming in this case that it's the same sourcetype as both sources had the same specific fields): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="A" sourcetype="B" source="ABC" | eval R1 = TS1| join sourcetype [search index="X" sourcetype="B" source="ABC1" | eval R2 = TS2 | fields - R2] | eval diff(R2-R1) = R2-R1 | table diff(R2-R1), R1, R2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want just the latest event from each source you could add a dedup command like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index="A" sourcetype="B" source="ABC" | dedup source | eval R1 = TS1| join sourcetype [search index="X" sourcetype="B" source="ABC1" | eval R2 = TS2 | fields - R2] | eval diff(R2-R1) = R2-R1 | table diff(R2-R1), R1, R2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Perhaps not the most beautiful way to do it but I find it clear. Will not work well in real time.&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;BR /&gt;
Victor&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 06:56:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184511#M53135</guid>
      <dc:creator>victorrosberg</dc:creator>
      <dc:date>2015-08-25T06:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields from different files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184512#M53136</link>
      <description>&lt;P&gt;Thanks..this query was helpfull&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 13:43:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184512#M53136</guid>
      <dc:creator>loureni1</dc:creator>
      <dc:date>2018-03-20T13:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields from different files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184513#M53137</link>
      <description>&lt;P&gt;Feel free to upvote if this helped!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 15:01:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-from/m-p/184513#M53137</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2018-03-20T15:01:25Z</dc:date>
    </item>
  </channel>
</rss>

