#!/usr/bin/gawk -f # ------------------------------------------------------------------- # Copyright (C) 2014 by Intevation GmbH # Author(s): # Sascha Wilde # This program is free software under the GNU GPL (>=v2) # Read the file COPYING coming with the software for details. # ------------------------------------------------------------------- function liststr(array) { str = "" for (i in array) str = str "," i # cut off leading comma return substr(str, 2) } # ------------------------------------------------------------------- { if (keys[$2" "$3]) keys[$2" "$3]=keys[$2" "$3]","$1 else keys[$2" "$3]=$1 } END { for (key in keys) { split(keys[key], hosts, ",") asort(hosts) delete hostlist delete iplist # we save hosts as array subscripts to eleminate duplicates for (j in hosts) { host=hosts[j] if (match(host, "^[a-z]")) hostlist[host] else iplist[host] } hoststr = liststr(hostlist) ipstr = liststr(iplist) print( hoststr ( (hoststr && ipstr) ? "," : "" ) ipstr " " key) } }