Friday, October 22, 2021

AWK: count which customer has the most unique accounts

Content of the count_uniq.awk script:


BEGIN {
    FS=",";
}
{
    if ($0 in seen == 0){arr[$2]++} else {seen[$0]=1}
    seen[$0]=1;
}
END {
    for (a in arr) print a, arr[a]
}


What it does?

count how many accounts does each customer has, ignoring duplicated rows. Details as in image below:


Customer "a" has 3 different accounts: [1, 2, 3]

Customer "b" has 1 account: [2]

Customer "c" has 2 accounts: [1, 2]


No comments:

Post a Comment

Any comments?

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...