Skip to content

Commit

Permalink
[group] READMEに説明追加 #19
Browse files Browse the repository at this point in the history
  • Loading branch information
onozaty committed Jan 12, 2022
1 parent 3353c9f commit 638ee55
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [concat](#concat) Concat CSV files.
* [count](#count) Count the number of records.
* [exclude](#exclude) Exclude rows by included in another CSV file.
* [group](#group) Aggregate by group.
* [filter](#filter) Filter rows by condition.
* [head](#head) Show head few rows.
* [header](#header) Show header.
Expand Down Expand Up @@ -349,6 +350,66 @@ col1,col2
4,D
```

## group

Group by the value of the specified column and perform aggregation.

Currently, only counting is supported.
It's like `GROUP BY` + `COUNT` in SQL.

### Usage

```
csvt group -i INPUT -c COLUMN [--count-column COUNT_COLUMN] -o OUTPUT
```

```
Usage:
csvt group [flags]
Flags:
-i, --input string Input CSV file path.
-c, --column string Name of the column to use for grouping.
--count-column string (optional) Column name for the number of records. (default "COUNT")
-o, --output string Output CSV file path.
-h, --help help for group
```

### Example

The contents of `input.csv`.

```
col1,col2
1,B
2,B
3,A
4,D
5,C
6,D
7,D
8,E
9,A
10,D
```

Group the rows by the value of `col2` and aggregate the number of rows.

```
$ csvt group -i input.csv -c col2 -o output.csv
```

The contents of the created `output.csv`.

```
col2,COUNT
A,2
B,2
C,1
D,4
E,1
```

## filter

Create a new CSV file by filtering the input CSV file to rows that match the conditions.
Expand Down

0 comments on commit 638ee55

Please sign in to comment.