mirror of
https://github.com/nushell/nushell
synced 2025-01-01 07:48:53 +00:00
bce6f5a3e6
* uniq: Add counting option (WIP!) Usage: fetch https://raw.githubusercontent.com/timbray/topfew/master/test/data/access-1k | lines | wrap item | uniq | sort-by count | last 10 * uniq: Add first test * uniq: Re-enable the non-counting variant. * uniq: Also handle primitive lines. * uniq: Update documentation * uniq: Final comment about error handling. Let's get some feedback * uniq: Address review comments. Not happy with the way I create a TypeError. There must be a cleaner way. Anyway, good for shipping. * uniq: Use Labeled_error as suggested by jturner in chat. * uniq: Return error directly. Co-authored-by: Christoph Siedentop <christoph@siedentop.name>
49 lines
No EOL
1.5 KiB
Markdown
49 lines
No EOL
1.5 KiB
Markdown
# uniq
|
|
|
|
Returns unique rows or values from a dataset.
|
|
|
|
## Examples
|
|
|
|
Given a file `test.csv`
|
|
|
|
```
|
|
first_name,last_name,rusty_at,type
|
|
Andrés,Robalino,10/11/2013,A
|
|
Andrés,Robalino,10/11/2013,A
|
|
Jonathan,Turner,10/12/2013,B
|
|
Yehuda,Katz,10/11/2013,A
|
|
```
|
|
|
|
```
|
|
> `open test.csv | uniq`
|
|
━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━
|
|
# │ first_name │ last_name │ rusty_at │ type
|
|
───┼────────────┼───────────┼────────────┼──────
|
|
0 │ Andrés │ Robalino │ 10/11/2013 │ A
|
|
1 │ Jonathan │ Turner │ 10/12/2013 │ B
|
|
2 │ Yehuda │ Katz │ 10/11/2013 │ A
|
|
━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━
|
|
```
|
|
|
|
```
|
|
> `open test.csv | get type | uniq`
|
|
━━━┯━━━━━━━━━
|
|
# │ <value>
|
|
───┼─────────
|
|
0 │ A
|
|
1 │ B
|
|
━━━┷━━━━━━━━━
|
|
```
|
|
|
|
### Counting
|
|
`--count` or `-c` is the flag to output a `count` column.
|
|
|
|
```
|
|
> `open test.csv | get type | uniq -c`
|
|
───┬───────┬───────
|
|
# │ value │ count
|
|
───┼───────┼───────
|
|
0 │ A │ 3
|
|
1 │ B │ 2
|
|
───┴───────┴───────
|
|
``` |