Skip to content

Latest commit

 

History

History
178 lines (117 loc) · 4.6 KB

File metadata and controls

178 lines (117 loc) · 4.6 KB

select

Select, re-order, reverse, duplicate or drop columns.

Table of Contents | Source: src/cmd/select.rs | 👆

Description | Examples | Usage | Arguments | Select Options | Common Options

Description

Select columns from CSV data efficiently.

This command lets you manipulate the columns in CSV data. You can re-order, duplicate, reverse or drop them. Columns can be referenced by index or by name if there is a header row (duplicate column names can be disambiguated with more indexing). Column ranges can also be specified. Finally, columns can be selected using regular expressions.

Examples

Select the first and fourth columns

qsv select 1,4

Select the first 4 columns (by index)

qsv select 1-4

Select the first 4 columns (by name)

qsv select Header1-Header4

Ignore the first 2 columns (by range)

qsv select 3-

Ignore the first 2 columns (by index)

qsv select '!1-2'

Select the third column named 'Foo':

qsv select 'Foo[2]'

Select the first and last columns, _ is a special character for the last column:

qsv select 1,_

Reverse the order of columns:

qsv select _-1

select columns starting with 'a' (regex)

qsv select /^a/

select columns with a digit (regex)

qsv select '/^.*\d.*$/'

remove SSN, account_no and password columns (regex)

qsv select '!/SSN|account_no|password/'

Sort the columns lexicographically (i.e. by their byte values)

qsv select 1- --sort

Select some columns and then sort them

qsv select 1,4,5-7 --sort

Randomly shuffle the columns:

qsv select 1- --random

Randomly shuffle the columns with a seed

qsv select 1- --random --seed 42

Select some columns and then shuffle them with a seed:

qsv select 1,4,5-7 --random --seed 42

Re-order and duplicate columns arbitrarily using different types of selectors

qsv select 3-1,Header3-Header1,Header1,Foo[2],Header1

Quote column names that conflict with selector syntax:

qsv select '\"Date - Opening\",\"Date - Actual Closing\"'

For more examples, see tests.

Usage

qsv select [options] [--] <selection> [<input>]
qsv select --help

Arguments

  Argument    Description
 <selection>  The columns to select. You can select columns by index, by name, by range, by regex and any combination of these. If the first character is '!', the selection will be inverted. If the selection contains embedded spaces or characters that conflict with selector syntax, it must be quoted. See examples above.

Select Options

     Option      Type Description Default
 ‑R,
‑‑random 
flag Randomly shuffle the columns in the selection.
 ‑‑seed  string Seed for the random number generator.
 ‑S,
‑‑sort 
flag Sort the selected columns lexicographically, i.e. by their byte values.

Common Options

     Option      Type Description Default
 ‑h,
‑‑help 
flag Display this message
 ‑o,
‑‑output 
string Write output to instead of stdout.
 ‑n,
‑‑no‑headers 
flag When set, the first row will not be interpreted as headers. (i.e., They are not searched, analyzed, sliced, etc.)
 ‑d,
‑‑delimiter 
string The field delimiter for reading CSV data. Must be a single character. (default: ,)

Source: src/cmd/select.rs | Table of Contents | README