join two csv files with key value

后端 未结 3 670
故里飘歌
故里飘歌 2020-12-16 00:47

I have two csv files, I want to join them using a key value, the column of the city.

One csv file, d01.csv has this form,

Barcelona, 19.5, 29.5
Tarra         


        
3条回答
  •  有刺的猬
    2020-12-16 00:57

    This awk may do:

    awk 'FNR==NR {a[$1]=$2FS$3FS$4;next} $1 in a {print $0,a[$1]}' OFS=", " d02,csv d01csv
    Barcelona, 19.5, 29.5, 20140916, 19.9, 28.5
    Tarragona, 20.4, 31.5 , 20140916, 21.4, 30.5
    Lleida, 16.5, 33.5 , 20140916, 17.5, 32.5
    

提交回复
热议问题