Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

nawk is truncating output

$
0
0
Legends,

I have 2 files f1 and f2. when i use nawk to compare the difference(subtraction) from 4th column of the file, it truncates the output.
can you please help to resolve this.

subtraction is (4th col of f1 - 4th col of f2). but it gives only below lines out of 116. I want to print all the lines of the file even if there is diff or no diff. :wall:

Code:

san:/tmp> wc -l f1 f2 | grep -v total
    116 f1
    116 f2

san:/tmp> head -3 f1 f2
==> f1 <==
TSCparser1 1irons1 EMEA_01 3
TSCparser12 1irons1 SPAIN_01 0
TSCparser13 1irons1 GERMANY_03 0

==> f2 <==
TSCparser1 1irons1 EMEA_01 3
TSCparser12 1irons1 SPAIN_01 0
TSCparser13 1irons1 GERMANY_03 0

san:/tmp> nawk 'FNR==NR{a[$1,$2,$3]=$4;next}{if(a[$1,$2,$3]){print $1,$2,$3,(a[$1,$2,$3]-$4)" times gapped in past 1 hr."}}' OFS="        " f1 f2
TSCparser1        1irons1        EMEA_01        0 times gapped in past 1 hr.
TSCparser94        1irons1        LSE_01        0 times gapped in past 1 hr.
TSCparser43        4irons1        STUTTGART_04        0 times gapped in past 1 hr.
TSCparser44        4irons1        STUTTGART_05        0 times gapped in past 1 hr.
TSCparser46        4irons1        STUTTGART_07        0 times gapped in past 1 hr.
TSCparser47        4irons1        STUTTGART_08        0 times gapped in past 1 hr.


Viewing all articles
Browse latest Browse all 16232

Trending Articles