awk '{ file_list[$1] += $2 list_length[$1] += 1}END{ for(key in file_list){ print list_length[key] " " key " " file_list[key] }}' file