Skip to main content
add sed-like syntax
Source Link
jubilatious1
  • 3.9k
  • 10
  • 21

...using Raku's sed-like syntax (doesn't validate CSV):

~$ raku -pe 's:4th/\,/|/;'  adnan_noor.txt

...or validating CSV with Raku's Text::CSV module:

Here isSecond answer above: Here's a way to manipulate even huge CSV files using Raku, in conjunction with the ecosystem's Text::CSV module. First we call the module at the command line (identical to Perl). Then we declare a $fh filehandle and open the source file for :r reading-only. From here we instantiate a $parser object, that can take parameters such as e.g. eol => \r\n (for MS Windows).

...using Raku's Text::CSV module:

Here is a way to manipulate even huge CSV files using Raku, in conjunction with the ecosystem's Text::CSV module. First we call the module at the command line (identical to Perl). Then we declare a $fh filehandle and open the source file for :r reading-only. From here we instantiate a $parser object, that can take parameters such as e.g. eol => \r\n (for MS Windows).

...using Raku's sed-like syntax (doesn't validate CSV):

~$ raku -pe 's:4th/\,/|/;'  adnan_noor.txt

...or validating CSV with Raku's Text::CSV module:

Second answer above: Here's a way to manipulate even huge CSV files using Raku, in conjunction with the ecosystem's Text::CSV module. First we call the module at the command line (identical to Perl). Then we declare a $fh filehandle and open the source file for :r reading-only. From here we instantiate a $parser object, that can take parameters such as e.g. eol => \r\n (for MS Windows).

added 35 characters in body
Source Link
jubilatious1
  • 3.9k
  • 10
  • 21

Which means,   "| "bar'bar-flatten"flatten' the first 3 columns (treat them as separate entities), join the next two columns on | pipe, and follow with the last column." If If we interpose this text-manipulation statement, we get back the desired Sample Output (above). Note how this code auto-quotes the whitespace-containing field by default.

https://github.com/Tux/CSV/blob/master/doc/Text-CSV.md
https://unix.stackexchange.com/a/791643/227738
https://github.com/Tux/CSV
https://raku.org

Which means, "| "bar-flatten" the first 3 columns, join the next two columns on | pipe, and follow with the last column." If we interpose this text-manipulation statement, we get back the desired Sample Output (above). Note how this code auto-quotes the whitespace-containing field by default.

https://unix.stackexchange.com/a/791643/227738
https://github.com/Tux/CSV
https://raku.org

Which means,   "| 'bar-flatten' the first 3 columns (treat them as separate entities), join the next two columns on | pipe, and follow with the last column." If we interpose this text-manipulation statement, we get back the desired Sample Output (above). Note how this code auto-quotes the whitespace-containing field by default.

https://github.com/Tux/CSV/blob/master/doc/Text-CSV.md
https://unix.stackexchange.com/a/791643/227738
https://raku.org

added 33 characters in body
Source Link
jubilatious1
  • 3.9k
  • 10
  • 21

Here is a way to manipulate even huge CSV files using Raku, in conjunction with the ecosystem's Text::CSV module. First we call the module at the command line (identical to Perl). Then we declare a $fh filehandle and open the source file for :r reading-only. From here we instantiate a $parser object, that can take parameters such as e.g. eol => \r\n (for MS Windows).

Until the $fh filehandle reaches eof end-of-file, we getline() get each line and save it to an Arrayarray named @ln (short for line"line"). If we output here we'd see all six (6) columns condensed to one column, reading col 1,2,3,4,5,6 over-and-over. ( To simply output a CSV file from here, we would use @ln.=rotor(6) andto get-back the a valid, single CSV row ).

Which means, "| bar"bar-flatflatten" the first 3 columns, join the next two columns on | barpipe, and follow with the last column." If we interpose this text-manipulation statement, we get back the desired Sample Output (above). Note how this code auto-quotes the whitespace-containing field by default.

Here is a way to manipulate even huge CSV files using Raku with the ecosystem's Text::CSV module. First we call the module at the command line (identical to Perl). Then we declare a $fh filehandle and open the source file for :r reading-only. From here we instantiate a $parser object, that can take parameters such as e.g. eol => \r\n (for MS Windows).

Until the $fh filehandle reaches eof end-of-file, we getline() get each line and save it to an Array @ln (short for line). If we output here we'd see all six (6) columns condensed to one column, reading col 1,2,3,4,5,6 over-and-over. ( To simply output a CSV file from here, we would use @ln.=rotor(6) and get-back the a valid CSV row ).

Which means, "| bar-flat the first 3 columns, join the next two columns on | bar, and follow with the last column." If we interpose this text-manipulation statement, we get back the desired Sample Output (above). Note how this code auto-quotes the whitespace-containing field by default.

Here is a way to manipulate even huge CSV files using Raku, in conjunction with the ecosystem's Text::CSV module. First we call the module at the command line (identical to Perl). Then we declare a $fh filehandle and open the source file for :r reading-only. From here we instantiate a $parser object, that can take parameters such as e.g. eol => \r\n (for MS Windows).

Until the $fh filehandle reaches eof end-of-file, we getline() get each line and save it to an array named @ln (short for "line"). If we output here we'd see all six (6) columns condensed to one column, reading col 1,2,3,4,5,6 over-and-over. ( To simply output a CSV file from here, we would use @ln.=rotor(6) to get-back a valid, single CSV row ).

Which means, "| "bar-flatten" the first 3 columns, join the next two columns on | pipe, and follow with the last column." If we interpose this text-manipulation statement, we get back the desired Sample Output (above). Note how this code auto-quotes the whitespace-containing field by default.

added 52 characters in body
Source Link
jubilatious1
  • 3.9k
  • 10
  • 21
Loading
added 5 characters in body
Source Link
jubilatious1
  • 3.9k
  • 10
  • 21
Loading
Source Link
jubilatious1
  • 3.9k
  • 10
  • 21
Loading