sort - Sort data files NAME: sort - Sort data files SYNOPSIS: sort [-bdfinrt?uv] [-[bdfinrt?]km1.n1,m2.n2] [-oOUTFILE] [file ...] DESCRIPTION: Sort all of the named files together and write the result to the standard output. The standard input is sorted if no file names are supplied; sort may be used as a filter. The default sort is ascending in ASCII sequence using the entire line, with upper and lower case considered different. Up to 10 key fields may be specified. The presence of any of 'bdfinrt?' effects only the immediately following key field; if there are no key fields specified, they effect the default key. The '-o' option causes the sorted output to be written to the named output file instead of to the standard output. The output file may be the same as one of the input files. The '-b' (blank) option causes leading whitespace in the key field to be ignored. The '-d' (dictionary) option sorts in dictionary order; only letters, digits, and blanks are considered in the compare, all else is ignored. The '-f' (fold) option folds all letters into lower-case for comparisons. The '-i' (ignore) option causes all non-printing (whitespace) characters to be ignored. The '-k' option selects a field to be used as a sort key. Up to 10 key fields can be specified. The keys are in order of decreasing significance. Key fields are compared, beginning with the most significant one, until a not-equal key is found. Lines with all keys equal are further ordered using the entire line as an ASCII key. Any of 'bdfinrt?' may also be specified by a preceeding switch field. The format of this is: '-km1.n1,m2.n2'. m1.n1 = start-of-key position (1st char of the key). Page 2 sort - Sort data files m2.n2 = end-of-key position (the char after the key). m? = of fields to skip, from start of line (0 = start of line). In the absence of a "-t" flag, a field is defined as: optional whitespace, followed by one or more non-whitespace characters, up to but not including the next whitespace character. n? = of chars to skip, from start-of-field. m1.n1 if omitted means start-of-line. m2.n2 if omitted means end-of-line. Other than m2.n2 being omitted, any of the 4 numbers omitted means 0 for that number. Neither of these specifiers will go past the end-of-line. It is possible for a line to have a null key if the start-of-key is at or after the end-of-key, or at end-of-line. A null key is lower than any non-null key. If '-b' was specified, leading whitespace is skipped after advancing to the m1/m2 field, but before advancing by n1/n2 characters. The '-n' (numeric) compares by arithmetic value. The key field is taken to be a leading signed integer numeric string, and converted to a long integer (32-bits) for comparison. The '-r' (reverse) option reverses the sense of the comparison from ascending to descending. The '-t?' (terminator character) changes the definition of a "field" (see '-k') to: string of zero or more characters ending with the "?" character. The "?" character has the following format: ? - a single character (except backslash) stands for itself. \t - tab \s - space (blank) \# - the numeric string "#" is the octal value of the char. \\ - backslash character The '-u' (unique) option causes only the 1st line of a set of lines having equal keys to be output. Only the specified keys are considered in the definition of 'unique'. The '-v' (verbose) gives elapsed time, etc. Examples of key field selection: If a line is: "ABC DEF GHI" flag key field -k1 " DEF GHI" -bk1 "DEF GHI" -bk1.1 "EF GHI" Page 3 sort - Sort data files -bk1,2 "DEF " -k1,1 "" (null field) -k1.0,2.1 " DEF " -bk1.0,2.1 "DEF G" -k0.1,1.3 "BC DE" -k1.0,2.0 " DEF" -k0.5,1.0 "" (null field) If a line is: "ABC,DEFGHIJ,KLM" flag key field -t,k1 "DEFGHIJ,KLM" -t,k1,2 "DEFGHIJ," -t,k0.1,0.6 "BC,DE" -t,k1.0,0.10 "DEFGHI" Error messages: "Cannot create temp file" if the required temporary file cannot be created in the current directory. "Cannot open" if a file cannot be accessed for reading. "Cannot create" if a file cannot be created for writing. "Out of space" if the sort runs out of memory. The following messages occur on a fatal error. Get help. panic("Cannot reopen temp file.n"); panic("Empty run.n"); panic ("Too many keys specifiedn"); panic ("Invalid key field formatn"); panic("Unexpected end of filen"); The "native" C library currently lacks the ftell() function, Thus, the routine may be used only with the Decus (PDP-11 compatibility mode) library. FILES sort.tmp Authors: David Conroy - original Ray Van Tassle - Almost totally re-written. All the switches added, and vastly improved performance.