1
votes

hi i am posting as reference to prev. question extended question for previously answered awk find missing number in sequence from file1 and append to column in file2 where i want to genereate next available number in sequence after comparing as well from both files column $1,$2,$3

i tried did it like this way

awk 'NR==FNR{a[$0]=$0; next} $1 in a{print $0 && b[$NF]; next} {while(++c in b); print $0, c}' file1 file2 

it just return below: just 2,3,4,5

A-5 ID2548 A550 SEQ.8232 md5 8232 71192160 COMPRESSED 5 false 0 verfied _xx 2
A-5 ID2548 A550 SEQ.8233 md5 8233 71192160 COMPRESSED 2 true 0 verfied _xx 3
B-8 ID3285 A400 SEQ.59060 md5 192 209763200 UNCOMPRESSED 1 false 0 verfied _xx 4
B-8 ID3285 A400 SEQ.59060 md5 193 262192000 COMPRESSED 16 true 0 verfied _xx 5

file1

A-5 ID2548 A550 85 S-38 COMPRESSED 1
B-8 ID3285 A400 81 B-22 UNCOMPRESSED 1

file2

A-5 ID2548 A550 SEQ.8232 md5 8232 71192160 COMPRESSED 5 false 0 verfied _xx
A-5 ID2548 A550 SEQ.8233 md5 8233 71192160 COMPRESSED 2 true 0 verfied _xx
B-8 ID3285 A400 SEQ.59060 md5 192 209763200 UNCOMPRESSED 1 false 0 verfied _xx
B-8 ID3285 A400 SEQ.59060 md5 193 262192000 COMPRESSED 16 true 0 verfied _xx

desired result:

A-5 ID2548 A550 SEQ.8232 md5 8232 71192160 COMPRESSED 5 false 0 verfied _xx 2
A-5 ID2548 A550 SEQ.8233 md5 8233 71192160 COMPRESSED 2 true 0 verfied _xx 3
B-8 ID3285 A400 SEQ.59060 md5 192 209763200 UNCOMPRESSED 1 false 0 verfied _xx 2
B-8 ID3285 A400 SEQ.59060 md5 193 262192000 UNCOMPRESSED 16 true 0 verfied _xx 3
2

2 Answers

0
votes
awk 'NR==FNR{vals[$1,$NF]; next} {while (($1,++incr[$1]) in vals); print $0, incr[$1]}' file1 file2
0
votes

Adapted from the answer to your previous quesion:

awk 'NR==FNR {vals[$1,$2,$3,$NF]; next}
    {
        while (($1,$2,$3,++incr[$1,$2,$3]) in vals)
        print $0, incr[$1,$2,$3]
    }' file1 file2

When reading file1, the key fields ($1,$2 & $3 in this case) are added to the array of already used values. They are separated by a comma – awk will use a special variable SUBSEP to implement a multi-dimensional array.

When reading file2 the sequentially incremented variable is an array which references the associated key fields.