Skip to main content
add Addendum
Source Link
jubilatious1
  • 3.9k
  • 10
  • 21

Using Raku (formerly known a Perl_6)

raku -MText::CSV -e 'my @a = csv(in => $*IN); @a = [Z] @a; csv(in => @a, out => $*OUT);' 

Adding this to the excellent list of suggestions already posted. It should be obvious to Perl-aficionados that the Raku ecosystem is somewhat similar in the way Modules get loaded at the command line (e.g. -MText::CSV).

Note, the first and third statements above are a bare-bones way to validate/output CSV files using Raku. So CSV output will contain double-quoted strings where necessary.

This question asks for transposition, and thus the extra (second) statement transposes rows/columns (representation within the @a array).

Sample Input:

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

Sample Output:

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

ADDENDUM: Code below for those who absolutely insist their CSV files don't need validation by a CSV-parser (same output as above, sans double-quotes):

raku -e 'my @a = lines.map(*.split(",")); .join(",").put for [Z] @a;' 

OR

raku -e '.join(",").put for [Z] lines.map: *.split(",");' 

https://docs.raku.org/language/operators#index-entry-[]_(reduction_metaoperators)
https://github.com/Tux/CSV/blob/master/doc/Text-CSV.pdf
https://raku.org

Using Raku (formerly known a Perl_6)

raku -MText::CSV -e 'my @a = csv(in => $*IN); @a = [Z] @a; csv(in => @a, out => $*OUT);' 

Adding this to the excellent list of suggestions already posted. It should be obvious to Perl-aficionados that the Raku ecosystem is somewhat similar in the way Modules get loaded at the command line (e.g. -MText::CSV).

Note, the first and third statements above are a bare-bones way to validate/output CSV files using Raku. So CSV output will contain double-quoted strings where necessary.

This question asks for transposition, and thus the extra (second) statement transposes rows/columns (representation within the @a array).

Sample Input:

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

Sample Output:

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

https://docs.raku.org/language/operators#index-entry-[]_(reduction_metaoperators)
https://github.com/Tux/CSV/blob/master/doc/Text-CSV.pdf
https://raku.org

Using Raku (formerly known a Perl_6)

raku -MText::CSV -e 'my @a = csv(in => $*IN); @a = [Z] @a; csv(in => @a, out => $*OUT);' 

Adding this to the excellent list of suggestions already posted. It should be obvious to Perl-aficionados that the Raku ecosystem is somewhat similar in the way Modules get loaded at the command line (e.g. -MText::CSV).

Note, the first and third statements above are a bare-bones way to validate/output CSV files using Raku. So CSV output will contain double-quoted strings where necessary.

This question asks for transposition, and thus the extra (second) statement transposes rows/columns (representation within the @a array).

Sample Input:

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

Sample Output:

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

ADDENDUM: Code below for those who absolutely insist their CSV files don't need validation by a CSV-parser (same output as above, sans double-quotes):

raku -e 'my @a = lines.map(*.split(",")); .join(",").put for [Z] @a;' 

OR

raku -e '.join(",").put for [Z] lines.map: *.split(",");' 

https://docs.raku.org/language/operators#index-entry-[]_(reduction_metaoperators)
https://github.com/Tux/CSV/blob/master/doc/Text-CSV.pdf
https://raku.org

Source Link
jubilatious1
  • 3.9k
  • 10
  • 21

Using Raku (formerly known a Perl_6)

raku -MText::CSV -e 'my @a = csv(in => $*IN); @a = [Z] @a; csv(in => @a, out => $*OUT);' 

Adding this to the excellent list of suggestions already posted. It should be obvious to Perl-aficionados that the Raku ecosystem is somewhat similar in the way Modules get loaded at the command line (e.g. -MText::CSV).

Note, the first and third statements above are a bare-bones way to validate/output CSV files using Raku. So CSV output will contain double-quoted strings where necessary.

This question asks for transposition, and thus the extra (second) statement transposes rows/columns (representation within the @a array).

Sample Input:

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

Sample Output:

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

https://docs.raku.org/language/operators#index-entry-[]_(reduction_metaoperators)
https://github.com/Tux/CSV/blob/master/doc/Text-CSV.pdf
https://raku.org