awk -F, '{c[$1]++; t[$1]=$0} END {for(k in c) {if (c[k]==1) print t[k]}}'
uniq -u with specific column
Question
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.
Solution
OTHER TIPS
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}'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow