(Updated to correct the output format)
Using awk:
BEGIN { OFS = "," }
{ servers[$1] = (servers[$1] == "" ? "server:" $2 : servers[$1] "," "server:" $2 ) }
END {
$0 = ""
for (domain in servers)
$(++n) = sprintf("\"%s(server:%s)\"", domain, servers[domain])
print
}
This would add the servers as a comma-delimited string to the specific domain in the main block while parsing the input file. This is done by modifying the servers array which holds the servers for a particular domain (the domain is the key in the array).
In the END block, we loop over all keys/domains in the servers array and create an output record in the specified format.
Running this on the supplied data:
$ awk -f script.awk names.txt
"TADDomain(server:TADServer_1)","ABCDomain(server:ContractABCServer_1,server:ABC_server1)","LinkDomain(server:CoreLinkServer_1)"
A mostly equivalent bash script (requires bash 4.3+ for the associative array):
declare -A servers
while read domain server; do
servers[$domain]+="${servers[$domain]:+,}server:$server"
done <names.txt
for domain in "${!servers[@]}"; do
out+="${out:+,}\"$domain(server:${servers[$domain]})\""
done
printf '%s\n' "$out"
... but see "https://unix.stackexchange.com/questions/169716".