python - Combining 2 .csv files by common column -
So let me have Is the CCV file where the first line in file 1 is:
mpid, title, description, model, category id, category description, subcategory id, subcategory details, manufacturer id, manufacturer details, url, manufacturer (Brand) URL, image URL, AR value, price, ship price, stock, condition first line from file 2:
Regular price, sale price Buy the manufacturer's name, model number, retailer category, URL, Product Name, Availability, Shipping Cost, Dasha, MPID, Image URL, UPC, Details
and then filled with information in every other file.
As you can see, there is one common field in the MPID (file 1: call1, file 2: 9 column, where the first call call is 1).
I would like to create a new file which will combine by seeing these two files in this column (as in: If there is an MPID in both files, then this new MPID file With 2 lines from it and 2 from its line file). If an MPID only appears in one file, then it should also go into this composite file.
The files are not sorted in any way.
How can I do this on a Debian machine with a shell script or python?
Thank you.
Edit: Both files do not have a comma other than separator fields
sort -t, -k index1 file1 & gt; Sorted1 sort -t, -k index2 file2 & gt; Sorted2 join -t, -1 index -2 -2 index2-A1-A2 sorted 1 sorted 2
Comments
Post a Comment