shell - Compare two files using awk command recursively -


I want to compare two files, 1) Compare each query result. 2) Compare only the first row of the query output. 3) Compare the time (third column), the first file time is less than the second file, then print the pōnp and do nothing.

File1:

  C: \ script & gt; Call transaction 1OPOP c: \ script & gt; Selection ID, PO_ID, TIME, DES table ID is PO_NUM TIME DES ------- ------------ --------------- - ---- 11232323 1OPOP 2012-08-01-23.02.50.040000 Sample 11232324 1OPOP 2013-09-01-23.02.50.040000 Sample 11232325 1OPOP 2014-09- 01-23.02.50.040000 Sample 11232326 1OPOP 2015-09-01-23.02. 50.040000 sample 4 record (s) selected. C: \ script & gt; Call transaction 1XDXD C: \ script & gt; Selection ID, PO_ID, TIME, DES table ID PO_NUM TIME DES ------- ---------------- ----------- - --- 11232323 1XDXD 2012-07-01-23.02.50.040000 Sample 11232324 1XDXD 2013-09-01-23.02.50.040000 Sample 11232325 1XDXD 2014-08-01-23.02. 50.040000 sample 3 record (s) selected. C: \ script & gt; Call transaction 1IOIO c: \ script & gt; Selection ID, PO_ID, time, DES table ID is PO_NUM TIME DES ------- ---------------- ----------- - ---- 11232323 1IOIO 2011-06-01-23.02.50.040000 Sample 11232324 1IOIO 2012-09-01-23.02.50.040000 Sample 2 record (s) selected  

File 2:

  c: \ script & gt; Call transaction 1OPOP c: \ script & gt; ID ID, PO_ID, TIME, DES table ID PO_NUM TIME DES ------- ------------ --------------- - --- 11232323 1OPOP 2012-09-01-23.02. 50.040000 Sample 11232324 1OPOP 2013-09-01-23.02.50.040000 Sample 11232325 1OPOP 2014-09-01-23.02.50.040000 Sample 11232326 1OPOP 2015-09-01-23.02.50.040000 Sample 4 record (s) selected C: \ script & gt ; Call transaction 1XDXD C: \ script & gt; Selection ID, PO_ID, TIME, DES table ID PO_NUM TIME DES ------- ---------------- ----------- - --- 11232323 1XDXD 2012-08-01-23.02.50.040000 Sample 11232324 1XDXD 2013-09-01-23.02.50.040000 Sample 11232325 1XDXD 2014-08-01-23.02. 50.040000 sample 3 record (s) selected. C: \ script & gt; Call transaction 1IOIO c: \ script & gt; Selection ID, PO_ID, time, DES table ID is PO_NUM TIME DES ------- ---------------- ----------- - ---- 11232323 1IOIO 2011-05-01-23.02.50.040000 Sample 11232324 1IOIO 2012-09-01-23.02.50.040000 Sample 2 record (s) selected  

< Div class = "post-text" itemprop = "text">

An unusual example:

  awk '/ ^ --- / {b = 1; Next} B == 1 {If (NR == FNR) is a [$ 2] = $ 3; And if (a [$ 2]  

break here:

  • set B = 1 when the line "---" starts
  • when B == expects to process the first row of the first data
  • or to match a <] in file1 or compare it with Liksografik first time to file and print accordingly.

If ID For awk a bit more complicated.


Here is a slightly more complex version Land that can not be returned in the query results id s second file than the first:

  awk 'NR == Fanar {if ($ 0 ~ / ^ --- /) {b = 1} and if (b == 1) {a [$ 1 $ 2] = $ 3; b = 0} next} $ 1 in $ 2 {if (a [$ 1 $ 2] & lt; $ 3 print $ 2} 'file1 file2'  

the main difference is that the file1 and PO_NUM < Each code in / code> is based on both of the first result of the id . All the entries in the result for the second file have a mail id And the PO_NUM combination is checked in the array. Apart from this, because b matters only in the first file, I rearrange conditional tests a little bit.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -