Coder Social home page Coder Social logo

cn's Introduction

DEPRECATION NOTICE

I recently discovered the tool Miller (https://github.com/johnkerl/miller) and believe it to be a better tool for this job. It does what cn set out to accomplish and so much more. Therefore I am archiving this project and removing the Homebrew tap.


cn

Usage: cn [-d] [-h HEADERFILE] LABEL FILE

A handy little utility to give you the index (1-based) of a label/column name in a header of a CSV. Using the -d flag, only the data under the label/column name is returned.

For example:

$ cat data.csv
a,b,c
1,0,0
0,1,0
0,0,1

$ cn b data.csv
2

$ cn -d b data.csv
0
1
0

You can also use stdin:

$ cat data.csv | cn b -
2

$ cat data.csv | cn -d b -
0
1
0

This works well with other tools, e.g.:

$ cat data2.csv
a,b,c
1,2,3
4,5,6
7,8,9

$ cat data2.csv | cn -d b - | awk -F, '{s+=$1}END{print s}'
15

You can even provide the headers from another file, which works well when you are filtering data (coming in from grep via stdin, for example) and still want to select a column. For example, let's say you have the following data. You want to sum the metric_2 column for all rows with type == 'a':

$ cat data3.csv
type,metric_1,metric_2,metric_3
a,1,2,3
b,4,5,6
a,7,8,9

$ cat data3.csv | grep a | cn -h data3.csv -d metric_2 - | awk -F, '{s+=$1}END{print s}'
10

Installation

You can install easily with homebrew:

brew tap jefferickson/cn
brew install cn

Or from source:

go get github.com/jefferickson/cn
go install github.com/jefferickson/cn

cn's People

Contributors

jefferickson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.