I have some log files containing FQDNs that I need to aggregate at the third level (three.two.tld); to do that I split it, reverse print the desired number of levels:
awk '{print$2}' consolidated.txt|awk -F. '{for(i=NF;i>NF-3;i--){printf ".%s",$i};printf "\t%s\n",$0}'
Leading "." aside, that does what I need where NF>2, e.g.
.com.microsoft.mp fee3.delivery.mp.microsoft.com
However, microsoft.com becomes:
.com.microsoft.com.microsoft microsoft.com
Try as I might, I cannot get my head around how to handle second-level-only domains (example.com) whilst still aggregating the remainder at three. I've tried adding if statements to the array output, but with no success.
Can someone please point me in the right direction?
Aucun commentaire:
Enregistrer un commentaire