Reputation: 13
I have two files, fileA
(error code list and threshold value) and fileB
(error log) as below:
FileA
:
(ERRCODE-000004) 100
(ERRCODE-000090) 50
(ERRCODE-000110) 100
(ERRCODE-000092) 50
(ERRCODE-000419) 100
FileB
:
user@hostname 3 (ERRCODE-000003) This is error description
user@hostname 14 (ERRCODE-000090) This is error description
user@hostname 871 (ERRCODE-000090) This is error description
I want to print lines in FileB
that contain an error code from column one from FileA
and have an error count greater than the treshold value in fileA
.
(column three in fileB = column one in fileA) AND
(column two in fileB > column two in fileA )
Expected result:
user@hostname 871 (ERRCODE-000090) This is error description
I have tried
awk 'NR==FNR{a[$1]++;next}a[$3] && $2>=50' fileA fileB
but this has the second condition hardcoded ($2>=50
).
Upvotes: 1
Views: 37
Reputation: 33317
You can check the presence of a key in the array with the in
keyword:
awk 'NR==FNR{a[$1]=$2;next} $3 in a && $2>a[$3]' filea fileb
Note that this assumes that filea has a single entry per code
Upvotes: 1