Linux - join 2 CSV files

后端 未结 4 967
野趣味
野趣味 2020-12-17 18:36

I have 2 CSV files:

file_1 columns: id,user_id,message_id,rate
file_2 columns: id,type,timestamp

The relation between the files is that

4条回答
  •  别那么骄傲
    2020-12-17 19:00

    You can use the join command like this:

    join -t, -1 3 -2 1 -o 1.1 1.2 1.3 1.4 2.3 <(sort -t, -k 3,3 file1) <(sort file2)
    

    It first sorts the files (file1 is sorted by the 3rd field) and then joins them using the 3rd field of file1 and the 1st field of file2. It then outputs the fields you need.

提交回复
热议问题