Why doesn't this work? I've looked for so long and have found some pretty complex solutions, but I'm thinking this can be simplified and reused...sad :'(
Statement
awk -F"\t" '!seen[$3]++'
File
r1c1 r1c2 r1c3
r2c1 r2c2 r2c3
r3c1 r3c2 r3c3
r4c1 r4c2 r3c3
r5c1 r5c2 r5c3
Desired Output
r3c1 r3c2 r3c3
r4c1 r4c2 r3c3
Code adds a 0 and 1.
[user@host]$ awk '{a[$3]=a[$3] $0 RS c[$3]++} END {for (i in c) if (c[i]>1) printf "%s",a[i]}' file
r3c1 r3c2 r3c3
0r4c1 r4c2 r3c3
1[jcole@dukescri01 srlg]$
In awk, one-pass version that stores records to hash:
$ awk '
{
a[$3]=a[$3] $0 RS # store records
c[$3]++ # counter
}
END {
for(i in c)
if(c[i]>1) # pick the ones with duplicates
printf "%s",a[i]
}' file
r3c1 r3c2 r3c3
r4c1 r4c2 r3c3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With