I've the input files with fields separated with colon:
main:
one:111:222:333
fiv:333:222:333
two:123:234:500
file1:
one:111:222:333
two:123:234:501
file2:
one:111:222:333
thr:-:234:232
fiv:999:500:232
Thanks to hints on [link][1] I have a bit modified awk code:
$ awk -F':' -vf=main 'FILENAME==f{m=$0};FILENAME!=f&&$2~/[0-9]+/{if ($2~/[0-9]+/&&(!($1 in a) || $3 > a[$1])) { a[$1] = $3; b[$1] = $0 } next;}{if (($1 in a) && (a[$1] > $3)){ print b[$1]":updated:"m; delete b[$1] } else print; }' file* main
thr:-:234:232
one:111:222:333
fiv:999:500:232:updated:fiv:333:222:333
two:123:234:500
Why it prints also line ``thr:-:234:232``?
As ``thr`` does not occur in main file, it should be ignored for any update in it.
Updated should be only these lines basing on 1st column, which exists in main file and corresponding lines with 1st column exist in file1 or file2 and have bigger value in 3rd column.
Why ``$2~/[0-9]+/`` does not work here?
[1]: https://unix.stackexchange.com/questions/433302