Merge rows from two CSV files

stefanaalten

Board Regular
Joined
Feb 1, 2011
Messages
71
Office Version
  1. 365
Platform
  1. Windows
I'm trying to figure out a way to accomplish the following:

I have a file ("books.csv") generated by an application (ComicRack) which lists books, one per line, unordered, approx. 4,000, as follows: Series;Title;Number;Volume;Year. A new version of this file is produced on an ad hoc basis (when I run the report). I can't change the format of the file (including the ; as field separator) as that's preset by the application.

e.g. Michel Vaillant;Paddock;58;-1;1995

I want to record the "read status" of each book by editing "books.csv", e.g. simply adding a field at the end of each line so it becomes: Series;Title;Number;Volume;Year;Read. Call this file "books-read.csv".

e.g. Michel Vaillant;Paddock;58;-1;1995;read

The list of books in books.csv may change with new books being added, removed, changed.
The only changes to books-read.csv will be when I change the "read" field, so no books will be added, removed or changed (apart from the value of the "read" field).

How can I merge these files on a regular basis?

- Books removed from books.csv should also be removed from books-read.csv, irrespective of whether they have been read or not.
- Books added to books.csv should also be added to books-read.csv, but of course the "read" field will be missing / empty
- Books changed in books.csv should overwrite the matching book in books-read.csv.

Thanks for any help with this!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Do you still need help with this?

You want the output to be a new books-read.csv file based on the current books.csv and books-read.csv files. It seems that merging two sorted arrays should work. Start by reading the files into 2 arrays, keeping the "read" field separate so that the records in both arrays can be compared. Then sort both arrays. Then loop through the arrays and merge to a new array, copying the "read" field when the records match. Then output the new array to the new file.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top