Text Processing – Command Line Utility to Transpose a CSV File

csvtext processing

Given a file like so

First,Last,Age
Cory,Klein,27
John Jacob,Smith,30

Is there a command line utility to transpose the contents so the output appears like so

First,Cory,John Jacob
Last,Klein,Smith
Age,27,30

Best Answer

ruby -rcsv -e 'puts CSV.parse(STDIN).transpose.map &:to_csv' < in.csv > out.csv
Related Question