Question
My data as /tmp/1
9367543
9105616
9108177
8948074
8860323
9170406
9105616
I run and I get nothing
cat /tmp/1 | uniq -d
This is strange, since uniq -d
should
-d Only output lines that are repeated in the input.
How can you use uniq -d
?
Solution
You have to sort your data before you use uniq. It only removes/detects duplicates on adjacent lines.
OTHER TIPS
Try this to double check, it will output any lines which are duplicated:
cat /tmp/1 | awk 'seen[$0]++ == 1'
Oh, this is your problem:
cat /tmp/1 | sort | uniq -d
Sort it before running uniq!
awk '{_[$0]++}END{for(i in _)if(_[i]>1) print i}' /tmp/1
or just
awk '_[$0]++ == 1' file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow