LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-04-2008, 08:40 AM   #1
lmedland
LQ Newbie
 
Registered: Jun 2008
Location: England
Posts: 21

Rep: Reputation: 15
Question CSV file merge help


Hi,

Although I'm not a developer, I can pick things up when spoon fed a little :-)

Here is what I'm trying to accomplish (a friend suggested BASH for this)....

I have two CSV files, a demographics file and a financial file and I wish to merge them using a unique ID.


Demographics.csv

ID, surname, first name, address 1, address 2, address 3, address 4
8761, Jones, John, 10 Street, London, , NW1 4TT
36609, Smith, Ken, 10 Road, London, , NW1 6JJ
89877, Miller, Luke, 70 Something, Harlow, Essex, ES6 8JU
8786, Riley, Kim, 67 Runway, Grantham, , GR5 7FD
5432, Kendal, Clive, 89 Street, London, NW1 4TT


Finance.csv

ID, Balance
8761, 300.00
36609, -200.00
89877, 500.00


The third file which is my desired output would look like this:-

output.csv


ID, surname, first name, address 1, address 2, address 3, address 4, balance
8761, Jones, John, 10 Street, London, , NW1 4TT, 300.00
36609, Smith, Ken, 10 Road, London, , NW1 6JJ, -200.00
89877, Miller, Luke, 70 Something, Harlow, Essex, ES6 8JU, 500.00

Where no ID is found in finance.csv, do not write output in the output.csv

How would I ideally accomplish this? Code samples would be great if possible.

Many thanks for your help.
 
Old 06-04-2008, 08:44 AM   #2
clvic
Member
 
Registered: Feb 2008
Location: Rome, Italy
Distribution: OpenSuSE 11.x, vectorlinux, slax, Sabayon
Posts: 206
Blog Entries: 2

Rep: Reputation: 44
The join command is what you're looking for:
join demographics.csv finance.csv
will provide you with the desired output.
It has many options, anyway the example above should be ok for you
 
Old 06-04-2008, 11:11 AM   #3
lmedland
LQ Newbie
 
Registered: Jun 2008
Location: England
Posts: 21

Original Poster
Rep: Reputation: 15
Thank you clvic.

I used the following to generate what I needed:-


[HTML]join '/home/lmedland/Desktop/demo.csv' '/home/lmedland/Desktop/fin.csv' -t , > output.csv[/HTML]
 
  


Reply

Tags
bash, csv, join, merge


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
load a csv file into postgresql sailu_mvn Linux - Server 5 03-26-2010 02:56 PM
create chart from csv file wolfipa Linux - Software 6 01-31-2008 07:59 PM
CSV Merge CorvusE Programming 3 12-12-2007 03:37 PM
help extracting data from csv file willinusf Linux - General 10 10-27-2006 09:10 PM
CSV File AMMullan Programming 2 11-10-2003 12:49 AM


All times are GMT -5. The time now is 09:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration