Merge values for same key
awk, bash, linux, shell
Solution
You can use awk like this:
awk -F, '{a[$1] = a[$1] FS $2} END{for (i in a) print i a[i]}' file
a,100,131,102
b,200,203,301
We use `-F,` to use comma as delimiter and use array `a` to keep aggregated value.
Reference: Effective AWK Programming
Problem
Is that possible to use `awk` to values of same key into one row? For instance ``` a,100 b,200 a,131 a,102 b,203 b,301 ``` Can I convert them to a file like this: ``` a,100,131,102 b,200,203,301 ```