Count number of values of one column group by value of another column

UserYmY

I have a text file like this :

asn|prefix|ip|domain
25008|85.192.184.0/21|85.192.184.59|solusi-it.com
25008|85.192.184.0/21|85.192.184.59|samtimes.ru
131755|103.31.224.0/24|103.31.224.58|karosel-ind.com
131755|103.31.224.0/24|103.31.224.58|solusi-it.com
9318|1.232.0.0/13|1.234.91.168|solusi-it.com
9318|1.232.0.0/13|1.234.91.168|es350.co.kr

Is there a way that I can count number of unique ips on a unique domain with Linux Bash command and get a result like this?

domain|count_ip
solusi-it.com|3
samtimes.ru|1
karosel-ind.com|1
es350.co.kr|1
Gilles Quenot

With :

perl -F'\|' -lane '                                                            
    $. > 1 and $domains->{$F[3]}->{$F[2]}++;
    END{
        print "domain|count_ip";
        print $_, "|", scalar keys %{ $domains->{$_} } for keys %$domains;
    }
' file | tee new_file

The idea behind this is to use a HASH of HASH

$domains->{$F[3]}->{$F[2]}++

the $F[3] is the domain and $F[2] is the IP. Uniqueness is guarantee. A HASH key is always unique.

OUTPUT:

domain|count_ip
es350.co.kr|1
karosel-ind.com|1
samtimes.ru|1
solusi-it.com|3

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

COUNT values in one Column for Distinct Value in Another Column - EXCEL

From Java

Use Spark to group by consecutive same values of one column, taking Max or Min value of another column for each group

From Dev

How to count the number of values based on another column?

From Java

TSQL: Group by one column, count all rows and keep value on second column based on row_number

From Dev

Excel - calculate average of values in one column based on another grouping column. The number of rows is not constant per group

From Dev

MySQL Count values from one column with selecting a value from another column

From Dev

How to count distinct values in one column for each distinct value in another column in MS Excel?

From Dev

Count distinct records in one column with multiple values in another column

From Dev

SQL:Count of values in one column in relation to another column

From Dev

How to sum values of one column and group them by another column

From Dev

How to sum values of one column and group them by another column

From Dev

Retrieving count of column values based on another column value

From Dev

in R: make a new column that counts the number of times a value appears in one column but excludes NA values from another column

From Dev

sql count the number of times two values share the same value from another column

From Dev

How to increment values in one column with the reference of value in another column

From Dev

Get the sum of like values in one column for each value in another column

From Dev

How to get the maximum values in one column for each value of another column?

From Dev

How to increment values in one column with the reference of value in another column

From Dev

How do you group values in one column for each unique value in another R?

From Dev

MySQL Group by column, then count by another column

From Dev

MySQL Group by column, then count by another column

From Dev

how to count the number of values in an column column in excel

From Dev

How to count the number of times a value is in a column based on particular row values?

From Dev

count the number of values greater than each value in a column of an array in r

From Dev

Dataframe count of values in one column

From Dev

Group by duplicates by one column, but showing another column

From Dev

Group by duplicates by one column, but showing another column

From Dev

Concatenate column values against another column group

From Dev

Check if one value in one column is in another column

Related Related

  1. 1

    COUNT values in one Column for Distinct Value in Another Column - EXCEL

  2. 2

    Use Spark to group by consecutive same values of one column, taking Max or Min value of another column for each group

  3. 3

    How to count the number of values based on another column?

  4. 4

    TSQL: Group by one column, count all rows and keep value on second column based on row_number

  5. 5

    Excel - calculate average of values in one column based on another grouping column. The number of rows is not constant per group

  6. 6

    MySQL Count values from one column with selecting a value from another column

  7. 7

    How to count distinct values in one column for each distinct value in another column in MS Excel?

  8. 8

    Count distinct records in one column with multiple values in another column

  9. 9

    SQL:Count of values in one column in relation to another column

  10. 10

    How to sum values of one column and group them by another column

  11. 11

    How to sum values of one column and group them by another column

  12. 12

    Retrieving count of column values based on another column value

  13. 13

    in R: make a new column that counts the number of times a value appears in one column but excludes NA values from another column

  14. 14

    sql count the number of times two values share the same value from another column

  15. 15

    How to increment values in one column with the reference of value in another column

  16. 16

    Get the sum of like values in one column for each value in another column

  17. 17

    How to get the maximum values in one column for each value of another column?

  18. 18

    How to increment values in one column with the reference of value in another column

  19. 19

    How do you group values in one column for each unique value in another R?

  20. 20

    MySQL Group by column, then count by another column

  21. 21

    MySQL Group by column, then count by another column

  22. 22

    how to count the number of values in an column column in excel

  23. 23

    How to count the number of times a value is in a column based on particular row values?

  24. 24

    count the number of values greater than each value in a column of an array in r

  25. 25

    Dataframe count of values in one column

  26. 26

    Group by duplicates by one column, but showing another column

  27. 27

    Group by duplicates by one column, but showing another column

  28. 28

    Concatenate column values against another column group

  29. 29

    Check if one value in one column is in another column

HotTag

Archive