How to compare and sort 2 csv's to show difference

后端 未结 4 2008
我在风中等你
我在风中等你 2021-01-24 18:28

Hi I have 2 csv\'s in the following format, (basically a list of email and the number of times we have been emailed by that sender):

file1.csv

Email,Val         


        
4条回答
  •  孤城傲影
    2021-01-24 19:11

    if you want to keep the order

    awk to the rescue!

    $ awk  'BEGIN   {FS=OFS=","}
            NR==FNR {a[$1]=$2; next} 
            FNR==1  {print $1,$2"1",a[$1]"2"; next} 
                    {print $1,$2,a[$1]}' file2 file1
    
    Email,Value1,Value2
    email1@email.com,2,3
    email2@email.com,4,6
    email3@email.com,1,8
    email4@email.com,6,2
    

    note the order of files...

提交回复
热议问题