Greetings!
I have been trying to find out a way to take a CSV file with a large number of rows, and a very large number of columns (in the thousands) and convert the rows to a single column of data, where the first row is a header representing the attribute name and the subsequent series of rows contains the value.
For instance:
In my CSV:
Row1: (header) Letter, Weight, Color, Cost
Row2: A, 20, Blue, 5
Row3: DD, 200, Orange, 100
... (and so forth)
I am trying to get the output to be:
Letter,A
Weight,20
Color,Blue
Cost,5
Letter,DD
Weight,200
Color,Orange
Cost,100
I found this awk code is useful:
BEGIN {FS=OFS=","}
{
for (i=1;i<=NF;i++)
{
arr[NR,i]=$i;
if( big <= NF)
big=NF;
}
}
END {
for(i=1;i<=big;i++)
{
for(j=1;j<=NR;j++)
printf("%s%s",arr[j,i], (j==NR ? "" : OFS));
#printf("%s%s",arr[j,i], (j==NR ? "" : OFS));
print "";
}
}
but this combines the values:
Letter,A,DD
Weight,20,200
Color,Blue,Orange
Cost,5,100
So in the end, i want to keep them completely separate. I am sure the answer is simple, but I am new to awk/sed and am having some difficulties figuring out what the trouble is. Anybody that can help me out, I would learn tremendously from the example. Thank you in advance!!