tsort -- Sort a table on one or more columns.
tsort table columns
This task sorts an STSDAS-format table. The sort is done in place, so if you want to keep a copy of the unsorted table, you should copy it with the tcopy task before you do the sort. The column, or columns, on which to sort are specified using the parameter columns, which is a list of column names, or column name templates, separated by commas. The most significant column name is the first in the list---the column whose values are sorted; subsequent columns are used only to break ties. There are two flags, ascend and casesens. The ascend parameter determines whether the sort is done in ascending or descending order, if ascend = yes, the first row in the output table holds the lowest value (if the sorted column is numeric) or the first string in alpahabetic order (if the sorted column is a character string). If casesens = yes, upper case characters precede lower case characters. Otherwise, case is not significant in determining the sort order. When sorting a boolean column, "no" precedes "yes". Null table elements are always last in the sort, regardless of the value of ascend.
- table [file name template]
- Name of the table, or tables, to be sorted in-place. All tables are sorted on the same column or columns; if more than one table is specified all tables must have the column(s) specified by the columns parameter.
- columns [string]
- Column name or column name template describing columns on which sort will be performed. A column name template consists of a list of column names, or column patterns containing wildcard characters. Individual column names, or templates, are separated by commas or white space. The list of columns can be placed in a file and the name of the file passed to columns (preceded by a "@" character).
- (ascend = yes) [boolean]
- Sort the table in ascending order? If you want the table sorted in descending order, set ascend = no.
- (casesens = yes) [boolean]
- Are sorts on character columns to be case sensitive? If casesens = yes,
upper case letters will precede lower case letters. If casesens = no,
case is ignored by the sort operation.
1. Sort a table of star positions by right ascension and declination:
tt> tsort starcat.tab ra,dec
2. Sort a phone list. Make the sort case insensitive:
tt> tsort phone.tab lname,fname case-
3. Sort a star catalog so that all binary stars (i.e., a boolean column named binary) are first:
tt> tsort starcat.tab binary asc-
This task was written by Bernie Simon.