Compare two CSV files and copy field on match

Completed Posted Apr 15, 2009 Paid on delivery
Completed Paid on delivery

I had such a great experience the first time, thought I would try it again.

I would like to have a script (PHP or Perl running from Linux Command Line) that will compare two different fields in two different CSV files, and if it finds a match, it will copy a field from the first CSV file and put it in the second CSV file.

So if I have a column (selected via script variable or command line option) with ManufacturerID's, the first row has a ABC123 as a manufacturer ID in that field, it will search through a column in the second CSV file (again selected via script variable or command line option) and if it finds a match (cannot be case sensitive, if it finds abc123, it should still match it), it will then copy data from the same row in a second column from the first CSV file to a a column in the second CSV in the matching row(both again selectable as mentioned above).

CSV 1:

"abc123","Title","Description","0123456789"

"abc456","Title","Description","1234567890"

"123efg","Title","Description","4982757482"

CSV 2:

"Title","ABC123","Description",""

"Title","abc456",""Description",""

"Title","abc789","Description",""

First run for example, take abc123 (from column 1) in CSV 1 and search in CSV 2 for it in (in column 2) for it. Since it sees ABC123, it will then take 0123456789 from Column 4 in CSV 1 and put it in Column 4 in CSV 2. Same for abc456 since there is a match. It won't do anything with 123efg as it isn't found in CSV 2. So CSV 2 after it processes should look like this:

CSV 2:

"Title","ABC123","Description","0123456789"

"Title","abc456",""Description","1234567890"

"Title","abc789","Description",""

As mentioned above, I have different CSV files that put this data in different fields, so I will need to be able to change columns either via command line or variable within the script (at the top) and also the CSV file names. The program can either be in Perl or PHP and has to run from Linux Command Line.

PHP

Project ID: #3812673

About the project

39 proposals Remote project Active Apr 16, 2009

Awarded to:

bobpsl

See private message.

$21.25 USD in 5 days
(10 Reviews)
3.6

39 freelancers are bidding on average $49 for this job

meet2amitvw

See private message.

$38.25 USD in 5 days
(172 Reviews)
9.4
hits

See private message.

$76.5 USD in 5 days
(966 Reviews)
9.0
MuktoSoftware

See private message.

$51 USD in 5 days
(391 Reviews)
7.3
eperfections

See private message.

$25.5 USD in 5 days
(186 Reviews)
7.0
lambdasquare

See private message.

$85 USD in 5 days
(106 Reviews)
6.5
mzgymunt

See private message.

$29.75 USD in 5 days
(517 Reviews)
6.4
dpovshed

See private message.

$33.15 USD in 5 days
(46 Reviews)
5.9
cciontos

See private message.

$51 USD in 5 days
(46 Reviews)
4.6
czetxinc

See private message.

$76.5 USD in 5 days
(8 Reviews)
4.8
myvisl

See private message.

$7.65 USD in 5 days
(69 Reviews)
4.6
PixelSOFT

See private message.

$42.5 USD in 5 days
(54 Reviews)
4.7
dinarlol

See private message.

$85 USD in 5 days
(66 Reviews)
5.2
ultimatecode

See private message.

$42.5 USD in 5 days
(47 Reviews)
4.6
CodeScience

See private message.

$42.5 USD in 5 days
(13 Reviews)
4.6
b0tivw

See private message.

$67.15 USD in 5 days
(14 Reviews)
4.8
springleocn

See private message.

$34 USD in 5 days
(21 Reviews)
4.4
no1msd

See private message.

$42.5 USD in 5 days
(25 Reviews)
4.5
nusoftware

See private message.

$85 USD in 5 days
(20 Reviews)
4.4
wfaris

See private message.

$34 USD in 5 days
(3 Reviews)
4.0
adhd

See private message.

$21.25 USD in 5 days
(14 Reviews)
3.9