I have a two-column file:
1,112 1,123 2,123 2,124 2,144 3,158 4,123 4,158 5,123
I need to know last column2 value for each column1:
<
With GNU bash:
declare -A array # associative array # read from file while IFS=, read a b; do array[$a]="$b"; done < file # print array for i in "${!array[@]}"; do echo "$i,${array[$i]}"; done
Output:
1,123 2,144 3,158 4,158 5,123