title: Check and compare if time difference is less than 30 sec between all rows of a column based on another column
body: <p>In a shell script, I want to get all the records, if from file orders it contains 3 or more rows where firm is same and time (column2) difference is less than 30 seconds, if greater than 30 seconds than we exclude. I have tried using awk, but to no avail.</p>
  <p>The file <code>orders.csv</code> will have hundreds of rows:</p>
  <pre><code>date,time,firm,user,id
  20220520,12:00:00,TEST1,ABC,FNT0060
  20220520,12:00:05,TEST2,ABC,FNT0061
  20220520,12:00:10,TEST1,ABC,FNT0062
  20220520,12:00:25,TEST1,ABC,FNT0063
  20220520,12:00:45,TEST1,ABC,FNT0064
  ...
  </code></pre>
  <p>Expected output:</p>
  <pre><code>date,time,firm,user,id
  20220520,12:00:00,TEST1,ABC,FNT0060
  20220520,12:00:10,TEST1,ABC,FNT0062
  20220520,12:00:25,TEST1,ABC,FNT0063
  </code></pre>
  <p>Also, if for instance time in seconds in time column, &quot;01 02 29 31 32&quot; for the same frim, then it's fine either way we print 01,02,29 as only set or would print all records since we have 2 sets. 01 02 29 &amp; 29 31 32 since both are at the moment.</p>
  <p>I can get the time difference in time of a column alone, but not in comparison to above mentioned case:</p>
  <pre class="lang-bash prettyprint-override"><code>awk -F '[:,]' '{t=$2x3600+$3x60+$4} NR&gt;1{printf( &quot;%.6f\n&quot;, t-p)}{p=t}' $orders.csv &gt; abc.csv
  </code></pre>
  <p>Now <code>abc.csv</code> contains &quot;10,15&quot;</p>
  <p>The following command will get me 3 or more matching firm:</p>
  <pre class="lang-bash prettyprint-override"><code>awk -F',' 'NR==FNR{cnt[$3]++; next} cnt[$3]&gt;=3' $orders.csv $orders.csv &gt; firm.csv
  </code></pre>
  <p>Now, how can I combine such that I get expected result or any other way?</p>