Skip to main content
hopefully done...
Source Link
hyperslug
  • 13.7k
  • 4
  • 50
  • 62

RevisedRevision3:

You must sort both lists on email alphabetically. (If someone knows how to do that, then just copy this answer into yours)join. Given that the email field the 2nd field of file1 and the 1st field of file2:

joinsort -t , -1k 2 -,2 1 file1.csv file2.csv > file3sort1.csv

parameter meaning

sort -t , :-k '1,' is1 thefile2.csv field> separatorsort2.csv
-1 2join :-t file, -1, 2nd2 field
-2 1 : filesort1.csv 2,sort2.csv 1st> fieldsort3.csv

parameter meaning


-t ,   : ',' is the field separator
-k 2,2 : character sort on 2nd field
-k 1,1 : character sort on 1st field
-1 2   : file 1, 2nd field
-2 1   : file 2, 1st field
>      : output to file

produces


email,ID,name
email,ID,name
...

sorted by email alphabetically.

Note that if any email is missing from either file it will be omitted from the results.

Revised:

You must sort both lists on email alphabetically. (If someone knows how to do that, then just copy this answer into yours)

join -t , -1 2 -2 1 file1.csv file2.csv > file3.csv

parameter meaning

-t , : ',' is the field separator
-1 2 : file 1, 2nd field
-2 1 : file 2, 1st field

Note that if any email is missing from either file it will be omitted from the results.

Revision3:

You must sort both lists on email alphabetically, then join. Given that the email field the 2nd field of file1 and the 1st field of file2:

sort -t , -k 2,2 file1.csv > sort1.csv
sort -t , -k 1,1 file2.csv > sort2.csv
join -t , -1 2 -2 1 sort1.csv sort2.csv > sort3.csv

parameter meaning


-t ,   : ',' is the field separator
-k 2,2 : character sort on 2nd field
-k 1,1 : character sort on 1st field
-1 2   : file 1, 2nd field
-2 1   : file 2, 1st field
>      : output to file

produces


email,ID,name
email,ID,name
...

sorted by email alphabetically.

Note that if any email is missing from either file it will be omitted from the results.

added 282 characters in body
Source Link
hyperslug
  • 13.7k
  • 4
  • 50
  • 62

Assuming the email address is the leftmost field ofRevised:

You must sort both fileslists on email alphabetically. (If someone knows how to do that, trythen just copy this: answer into yours)

join 'file1.csv' 'file2.csv' -t , -1 2 -2 1 file1.csv file2.csv > file3.csv

parameter meaning

-t , : ',' is the field separator
-1 2 : file 1, 2nd field
-2 1 : file 2, 1st field

Note that if any email is missing from either file it will be omitted from the results.

Assuming the email address is the leftmost field of both files, try this:

join 'file1.csv' 'file2.csv' -t , > file3.csv

Revised:

You must sort both lists on email alphabetically. (If someone knows how to do that, then just copy this answer into yours)

join -t , -1 2 -2 1 file1.csv file2.csv > file3.csv

parameter meaning

-t , : ',' is the field separator
-1 2 : file 1, 2nd field
-2 1 : file 2, 1st field

Note that if any email is missing from either file it will be omitted from the results.

Source Link
hyperslug
  • 13.7k
  • 4
  • 50
  • 62

Assuming the email address is the leftmost field of both files, try this:

join 'file1.csv' 'file2.csv' -t , > file3.csv