I have two CSV files that share similar headers:sample_scv_1.csv is::
Transaction_date,Name,Payment_Type,Product
1/2/09 6:17,NA,Mastercard,NA
1/2/09 4:53,NA,Visa,NA
1/2/09 13:08,Nick,Mastercard,NA
1/3/09 14:44,Larry,Visa,Goods
1/4/09 12:56,Tina,Visa,Services
1/4/09 13:19,Harry,Visa,Goods
Similarly, sample_scv_2.csv is ::
Transaction_date,Product,Name
1/2/09 6:17,Goods,Janis
1/2/09 4:53,Services,Nicola
1/2/09 13:08,Materials,Asuman
Here in these two files Columns/Fields Transaction_date, Product, Name are common and I want to replace fields Product, Name in sample_scv_1.csv iff the transaction date matches in both the files.
This is a toy example and my file is big. For this example I can separate the cases where columns are equal and use indices to replace using csvtool as:
head -4 sample_scv_1.csv > temp1.csv
tail -3 sample_scv_1.csv > temp1_1.csv
#sudo apt-get install csvtool
csvtool pastecol 2,4 3,2 temp1.csv sample_scv_2.csv > temp1_2.txt
cat temp1_2.txt temp1_1.csv > sample_scv_1.csv
My required output is ::
Transaction_date,Name,Payment_Type,Product
1/2/09 6:17,Janis,Mastercard,Goods
1/2/09 4:53,Nicola,Visa,Services
1/2/09 13:08,Asuman,Mastercard,Materials
1/3/09 14:44,Larry,Visa,Goods
1/4/09 12:56,Tina,Visa,Services
1/4/09 13:19,Harry,Visa,Goods
I can determine until which line the transaction date matches but I can not know the indexes where the two columns overlap: like Name and Product in first file. One issue is easy as all columns of sample_scv_2.csv will be in sample_scv_1.csv. Any ways to do this efficiently.