I wanted to see different type of answers I receive from you guys for the below problem. I am curious to see below problem being solved completely through array or any other
With bash and sort:
#!/bin/bash
declare -A array # define associative array
# read file input.txt to array
while IFS=", " read -r line number; do
array["$line"]+=",$number"
done < input.txt
# print array
for i in "${!array[@]}"; do
echo "$i${array[$i]}"
done | sort
Output:
Name1,Phone1,Phone2 Name2,Phone2,Phone1 Name3,Phone1 Name4,Phone5,Phone1
Try this:
awk -F', ' '{a[$1]=a[$1]","$2}END{for(i in a) print i a[i]}' input.txt
Output:
Name1,Phone1,Phone2 Name2,Phone2,Phone1 Name3,Phone1 Name4,Phone5,Phone1