I want to determine if a record contains a duplicate value for a specific field and then delete the duplicate record and save the new file.
abc|123|def|456
abc|456|ghi|789
def|123|def|456
I want to save a new file with any record that duplicates field 1 removed.
abc|123|def|456
def|123|def|456
This awk code comes close, but actually does the opposite. It creates a new duplicate row and then saves it to the new file.
awk -F'|' 'myv=a[$1] !/^myv++/' file.txt > newFile.txt
awk -F'|' '!a[$1]++' file.txt > newFile.txt
– steeldriver Dec 11 '18 at 20:04