- Yair Mark
Today I had to clean up a CSV as well as add some columns to it. This ended up being much harder than I thought it would be.
I eventually found a solution using more common Unix tools.
But to fully understand the solution, pretend you have 3 CSVs with the same amount of rows:
This is a CSV we are using for the column in the combined CSV, it holds the ID of the rows:
We have another CSV with the actual data:
We have one last CSV with data we want to add to the end. In this case we are prepping data to be used with a Postgres copy command
Prentend the 3 files are named respectively:
After a bunch of Googling the easiest way to combine them is below:
paste -d ';' file-1.csv file-2.csv file-3.csv >> combined.csv
- We specify that
;is the delimiter
- We provide the file names in the order we wish to combine their columns
- We place the combined values in one new csv file called