Dynamic indirect Bash array

后端 未结 3 636
挽巷
挽巷 2021-01-29 00:03

I have logs in this format:

log1,john,time,etc
log2,peter,time,etc
log3,jack,time,etc
log4,peter,time,etc

I want to create a list for every per

3条回答
  •  孤街浪徒
    2021-01-29 00:19

    You can use awk. As a demo:

    awk -F, '{a1[$2]=a1[$2]" \""$0"\""; sum[$2]++} END{for (e in sum){print e"=("  "\""sum[e]"\""a1[e]")"}}' file
    john=("1" "log1,john,time,etc")
    peter=("2" "log2,peter,time,etc" "log4,peter,time,etc")
    jack=("1" "log3,jack,time,etc")
    

提交回复
热议问题