user93796
user93796

Reputation: 18379

joining two csv files based on a column

I have 2 csv files as follows

AllEmpployees.txt
EmpID,Name

QualifiedEmployeees.csv
Empid

Now i want to find names of qualified employees

Empid,Name

Am using following command

   join -t , -1 1 -2 1 QualifiedEmployeees.csv AllEmployees.txt

This results in zero records.Am sure that there is a intersection of employeeids.

Reference : https://superuser.com/questions/26834/how-to-join-two-csv-files

Is it because qualified employees file has only one column and there is no delimiter?Or am i doing something wrong

Upvotes: 2

Views: 6092

Answers (3)

Vijay
Vijay

Reputation: 67231

awk -F, 'FNR==NR{a[$1];next}($1 in a){print $2}' Qualiedemployees.txt allEmployees.txt

Upvotes: 0

Cyrus
Cyrus

Reputation: 88646

Try this:

join -t "," <(dos2unix <QualifiedEmployeees.csv) <(dos2unix <AllEmpployees.txt)

Upvotes: 2

John Zwinck
John Zwinck

Reputation: 249153

If join is not working (not producing as many rows as you expect, or no rows at all), it is likely because your input is not sorted. From man join we see this:

When the default field delimiter characters are used, the files to be joined should be ordered in the collating sequence of sort(1), using the -b option, on the fields on which they are to be joined, oth- erwise join may not report all field matches. When the field delimiter characters are specified by the -t option, the collating sequence should be the same as sort(1) without the -b option.

Upvotes: 0

Related Questions