Merge all csv files in directory column wise
0
votes
2
answers
1879
views
Say the directory contained 3 csv files:
The first csv:
Name, John
Age, 18
The second csv:
Name, Jim
Age, 21
The third csv:
Name, Amy
Age, 22
I would want the result to be:
Name, John, Jim, Amy
Age, 18, 21, 22
It's important to know the directory could have n many csvs
I have both bash and posix shell available
Edit:
This feels like it should work but still has an issue with regards to order:
awk -F, -v OFS="," '{a[FNR]=a[FNR]?a[FNR]FS$2:$1FS$2}END{for(x in a)print x,a[x]}' *.csv > results.csv
Which makes no sense as FNR 1 should be first in the array but it is printed last?
Asked by Tap
(35 rep)
Apr 20, 2022, 05:22 PM
Last activity: Nov 23, 2022, 10:28 AM
Last activity: Nov 23, 2022, 10:28 AM