I have a fixed width file like below, where 1-9 and 18-21 are the key. Depending on which I am trying to get the output file without duplicate.
In File
12345ABCD78.90200ABCD
12345ABCD90.45300ABCD
11111EFGH56.75100ABCD
12345ABCD34.45400ABCD
11111EFGH75.90200ABCD
Out File
12345ABCD34.45400ABCD
11111EFGH75.90200ABCD
I have Tried using awk as below but not able to get the last occurrence of the duplicate. Can anyone help more on this.
awk -v df=Duplicates_File.dat -v of=Output_wdout_Duplicate.dat '
(substr($0, 1, 18),substr($0, 174, 3)) in key {
print > df
next
}
{ key[substr($0, 1, 18),substr($0, 174, 3)]
print > of
}' Inputfile