DevHeads.net

csvutils - tools 'n' scripts for working with comma-separated values (csv) datafiles - the world's most popular tabular data interchange format in text

Hello,

I've put together a new library / gem called csvutils [1] that collects
scripts for wrangling with comma-separated values (csv) datafiles -
the world's most popular tabular data interchange format in text.

Try the help option `-h/--help` with the command line tools. Example:

$ csvhead -h # or
$ csvhead --help

resulting in:

Usage: csvhead [OPTS] datafile ...
-n, --num=NUM Number of rows
-h, --help Prints this help

Now try it with csvheader -h, csvstat -h, csvsplit -h, csvcut -h and so on.

Note: You can use all tools in your script using the CsvUtils class methods:

Shell => Ruby
csvhead => CsvUtils.head( path, n: 4 )
csvheader => CsvUtils.header( path )
csvstat => CsvUtils.stat( path, *columns )
csvsplit => CsvUtils.split( path, *columns )
csvcut => CsvUtils.cut( path, *columns, output: path)

Let's retry the sample from the reamde in a ruby script:

require 'csvutils'

CsvUtils.head( 'ENG.csv' )
# same as:
# $ csvhead ENG.csv

CsvUtils.header( 'ENG.csv' )
# same as:
# $ csvheader ENG.csv

CsvUtils.stat( 'ENG.csv', 'Team1', 'Team2' )
# same as:
# $ csvstat -c Team1,Team2 ENG.csv

CsvUtils.stat( 'AUT.csv', 'Season' )
# same as:
# $ csvstat -c Season AUT.csv

CsvUtils.split( 'AUT.csv', 'Season' )
# same as:
# $ csvsplit -c Season AUT.csv

CsvUtils.cut( 'AUT_2016-2017.csv', 'Date', 'Team1', 'Team2', 'FT1', 'FT2' )
# same as:
# $ csvcut -c Date,Team1,Team2,FT1,FT2 AUT_2016-2017.csv

Happy hacking and wrangling with comma-separated values (csv)
datafiles in ruby.
Cheers. Prost.

[1] <a href="https://github.com/csv11/csvutils" title="https://github.com/csv11/csvutils">https://github.com/csv11/csvutils</a>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>