associate multiple values for one key in array in bash

前端 未结 2 1344
情书的邮戳
情书的邮戳 2021-02-04 22:10

I have a text file that looks like:

1 aaaa
2 bbbb
3 cccc
4 ffffdd
2 eeee
2 ffff
4 gggg

I would like to map these into some sort of associative ar

2条回答
  •  情深已故
    2021-02-04 22:51

    The below script is for comma separated value, you can change as per your need

    awk -F "," '{OFS=","} 1 {if (a[$1]) {a[$1] = a[$1]" "$2} else {a[$1] = $2}} END {for (i in a)  { print i,a[i]}}'  input_file > Output_file
    

提交回复
热议问题