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
With perl :
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.
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.
Comments