Reputation: 6998
I want to print lines based on value in particular column that appear only once. In example below, val2 and val3 appear only once.
Input
val1,1
val2,2
val1,3
val3,4
Output
val2,2
val3,4
uniq -u
does not seem to have option of specifying a column. I also tried sort -t, -k1,1 -u
but that prints every row once.
Upvotes: 2
Views: 184
Reputation: 96258
awk -F, '{c[$1]++; t[$1]=$0} END {for(k in c) {if (c[k]==1) print t[k]}}'
Upvotes: 2
Reputation: 5167
Sounds like a problem for awk, assume that the command that produces
val1,1
val2,2
val1,3
val3,2
Is called foo
, then pipe it into awk like so:
foo | awk -F, '$2 == 2 {print}'
Upvotes: 1