LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using SED to compare two csv files and update accordingly (https://www.linuxquestions.org/questions/linux-newbie-8/using-sed-to-compare-two-csv-files-and-update-accordingly-4175509277/)

smokeyj 06-26-2014 10:58 AM

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.

smokeyj 06-26-2014 11:18 AM

UPDATE:
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.

schneidz 06-26-2014 11:27 AM

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 ?


All times are GMT -5. The time now is 10:58 PM.