The unix command uniq -u
returns truly unique elements (as opposed to the default behavior of uniq
). For example:
echo -e "a\na\nb\nc\nc\nd\ne\ne\ne\nf" | uniq -u
b
d
f
How can this command be emulated in a column-restricted manner (i.e., finding columns with unique elements from a table). One can assume that the input is already sorted. For example, taking column 1 as the desired unique column should give the following output:
echo -e "a\t1\na\t2\nb\t1\nc\t1\nc\t2\nd\t1\ne\t1\ne\t2\ne\t3\nf\t1" | some-command -col 1
b 1
d 1
f 1
Taking column 2 to be the desired unique column would give the following output:
echo -e "a\t1\na\t2\nb\t1\nc\t1\nc\t2\nd\t1\ne\t1\ne\t2\ne\t3\nf\t1" | some-command -col 2
e 3