Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-26-2014, 10:58 AM   #1
LQ Newbie
Registered: Jun 2014
Posts: 2

Rep: Reputation: Disabled
Using SED to compare two csv files and update accordingly

Hi All, I am nearly a complete newbie to Linux and I would like to ask your help to point me in the right direction if possible

I am currently building a prestashop ecommerce site

I need some advice on how to approach what I need to do regularly with two spreadsheet(CSV) files, one being the one from my supplier and the other being my master file used to build the product import CSV file for the prestashop server

The wholesaler regularly updates their product spreadsheet with new products and changes in pricing for existed products. Additionally the availability of products may change.

I need to find a way to compare both spreadsheets using the wholesaler’s SKU and

1. If SKU exists in both spreadsheets then the info on price and availability from the wholesaler’s spreadsheet should overwrite the values on my master spreadsheet

2. If SKU only exists on wholesaler spreadsheet, then my spreadsheet needs to have that SKU inserted exactly in the same position it has in the wholesaler’s spreadsheet, i.e. after the "same" previous SKU.

There are two other SED type scripts I need advice on too

How to append the text for one field (A) to the beginning of another (B), and to then append the text from a different field (C) to the end of (B)
How to fill in a column, with the titles from many other columns and the values
e.g. Feature; Height;1~Colour;4~ e.t.c
The product feature’s import needs everything to be in one cell.

I came up with the following
cat -E JoeTest.csv | sed ':a;N;$!ba;s/\n/<div><div\/> /g'

just to remove the white space in my product description field and add paragraphs. This took me so much time that I decided I would ask for help with the above. Hoping someone here can help or at least point me to some resources that makes the learning process a lot less painfull.
Old 06-26-2014, 11:18 AM   #2
LQ Newbie
Registered: Jun 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
I just thought that it might be easier to just append the wholesalers CSV file with all the extra info in my master CSV file for matching SKU's. Then to use this as my new master csv file.
Old 06-26-2014, 11:27 AM   #3
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,258

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
a 10 line sample before-and-after mite be helpful ?

i would treat the wholesaler.csv as the master list (any sku from your master.csv thats not found on wholesaler.csv should be appended to wholesaler.csv).

i think the easiest way would be to simply append the 2 sheets and delete the 2nd occurrence of any possible duplicate sku ?

Last edited by schneidz; 06-26-2014 at 11:47 AM.


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
[SOLVED] Bash scripting problem: CSV list of filenames and actual files compare; Issue with plus symbol gn000we Linux - General 2 08-05-2013 06:57 PM
[SOLVED] use sed to break up a csv file into several smaller files saphil Linux - General 2 05-23-2013 07:09 AM
sed with two .csv files - removal of lines. nas123 Linux - General 2 12-18-2012 09:59 AM
Please help compare 2 files via awk/sed Seemoi Programming 10 06-24-2012 01:23 PM
Compare two files using sed/grep xpto09 Linux - General 4 09-23-2011 10:20 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:50 AM.

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