warning warning warning This is a work-in-progress draft version.



xsv

From github: xsv:

xsv is a command line program for indexing, slicing, analyzing, splitting and joining CSV files. Commands should be simple, fast and composable:

  1. Simple tasks should be easy.
  2. Performance trade offs should be exposed in the CLI interface.
  3. Composition should not come at the expense of performance.

Installation

See xsv: installation for details.

Commands and documentation

From xsv --help:

$ xsv --help
Usage:
    xsv <command> [<args>...]
    xsv [options]

Options:
    --list        List all commands available.
    -h, --help    Display this message
    <command> -h  Display the command help message
    --version     Print version info and exit

Commands:
    cat         Concatenate by row or column
    count       Count records
    fixlengths  Makes all records have same length
    flatten     Show one field per line
    fmt         Format CSV output (change field delimiter)
    frequency   Show frequency tables
    headers     Show header names
    help        Show this usage message.
    index       Create CSV index for faster access
    input       Read CSV data with special quoting rules
    join        Join CSV files
    sample      Randomly sample CSV data
    search      Search CSV data with regexes
    select      Select columns from CSV
    slice       Slice records from CSV
    sort        Sort CSV data
    split       Split CSV data into many files
    stats       Compute basic statistics
    table       Align CSV data into columns

More description and examples can be found in the project's README.

Header based filtering

The headers command will list all the names of the columns, i.e. the first row elements. If you provide multiple input files, intersection of the headers will be shown.

$ cat scores.csv
Name,Maths,Physics,Chemistry
Ith,100,100,100
Cy,97,98,95
Lin,78,83,80

$ xsv headers scores.csv
1   Name
2   Maths
3   Physics
4   Chemistry

You can use the select command to print only the required columns based on column number (starting from 1) or header names.

# same as: xsv select 1,3 scores.csv
$ xsv select Name,Physics scores.csv
Name,Physics
Ith,100
Cy,98
Lin,83

# output order will be same as the select argument order
$ xsv select Maths,Name scores.csv 
Maths,Name
100,Ith
97,Cy
78,Lin

Pretty printing

The table command will align the input data column wise.

# same as: column -ts, scores.csv
$ xsv table scores.csv
Name  Maths  Physics  Chemistry
Ith   100    100      100
Cy    97     98       95
Lin   78     83       80

# example with quoted fields
$ cat quoted.csv 
apple,"10,000",50
fig,200,100
$ xsv table quoted.csv
apple  10,000  50
fig    200     100




More to come