3 ms·
awk '{ if (!($2 in seen)) print $0; seen[$2] = 1; }' You can even shorten this a bit! "awk '!seen[$2]++'" does the same thing -- awk will print the whole line
by gcmeplz 8y ago
awk '{ if (!($2 in seen)) print $0; seen[$2] = 1; }'
You can even shorten this a bit! "awk '!seen[$2]++'" does the same thing -- awk will print the whole line when it's provided a truthy value. It's definitely more code-golfy than being explicit about what's actually going on though
- bewuethr 8y agoDefinitely very terse, but I'd call this idiomatic awk.