Sort

Command

sort

sort {column}

Purpose

Sort a table's rows.

If no columns are specified, the rows are collated by comparing their values from left to right.

If columns are specified, the rows are collated using the specified columns only, in the order that they appear after the sort keyword.

The special keywords first and last are interpreted as the first (left-most) and last (right-most) columns of the table.

Use :first, :last, :before or :after to reference columns named first, last etc..

See also Sorting

Examples

psv sort

  • sort each table using the first column

psv sort value

  • Sort each table by its value column
  • Any tables wihtout a value column are sorted by their first column.

psv sort symbol value

  • Sort each table by their symbol and then value columns

psv sort value symbol

  • Sort each table by their value and then symbol columns
  • Note that the value column appears after the symbol column, so they are given additional priority markers to ensure the correct colation order.

psv sort value~v

  • Sort each table by their value column, in descending order

Playground "sort" example - default: sort using the left-most column % psv sort | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: specific column - "psv sort {name}" will sort using the values in a specific column % psv sort value | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: sorting by non-consecutive columns - "psv sort {name} {name}" will sort using the values in the specified columns % psv sort symbol value | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: sorting by columns in any order - the columns used for sorting do not need to be in left-to-right order - let's sort by value and then symbol % psv sort value symbol | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: changing sorting direction - the addition of `~` and a combination of flags can be used to change a column's type affiliation and sort direction - e.g `~v` will sort in descending order % psv sort value~v | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 |