150fc853eSJohn Marino.\" $OpenBSD: sort.1,v 1.45 2015/03/19 13:51:10 jmc Exp $ 250fc853eSJohn Marino.\" $FreeBSD: head/usr.bin/sort/sort.1.in 281123 2015-04-05 22:22:43Z pfg $ 37572dc55SJohn Marino.\" 47572dc55SJohn Marino.\" Copyright (c) 1991, 1993 57572dc55SJohn Marino.\" The Regents of the University of California. All rights reserved. 67572dc55SJohn Marino.\" 77572dc55SJohn Marino.\" This code is derived from software contributed to Berkeley by 87572dc55SJohn Marino.\" the Institute of Electrical and Electronics Engineers, Inc. 97572dc55SJohn Marino.\" 107572dc55SJohn Marino.\" Redistribution and use in source and binary forms, with or without 117572dc55SJohn Marino.\" modification, are permitted provided that the following conditions 127572dc55SJohn Marino.\" are met: 137572dc55SJohn Marino.\" 1. Redistributions of source code must retain the above copyright 147572dc55SJohn Marino.\" notice, this list of conditions and the following disclaimer. 157572dc55SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 167572dc55SJohn Marino.\" notice, this list of conditions and the following disclaimer in the 177572dc55SJohn Marino.\" documentation and/or other materials provided with the distribution. 187572dc55SJohn Marino.\" 3. Neither the name of the University nor the names of its contributors 197572dc55SJohn Marino.\" may be used to endorse or promote products derived from this software 207572dc55SJohn Marino.\" without specific prior written permission. 217572dc55SJohn Marino.\" 227572dc55SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 237572dc55SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 247572dc55SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 257572dc55SJohn Marino.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 267572dc55SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 277572dc55SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 287572dc55SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 297572dc55SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 307572dc55SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 317572dc55SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 327572dc55SJohn Marino.\" SUCH DAMAGE. 337572dc55SJohn Marino.\" 347572dc55SJohn Marino.\" @(#)sort.1 8.1 (Berkeley) 6/6/93 357572dc55SJohn Marino.\" 36*d6ca1884SSascha Wildner.Dd December 2, 2019 377572dc55SJohn Marino.Dt SORT 1 387572dc55SJohn Marino.Os 397572dc55SJohn Marino.Sh NAME 407572dc55SJohn Marino.Nm sort 4150fc853eSJohn Marino.Nd sort or merge records (lines) of text and binary files 427572dc55SJohn Marino.Sh SYNOPSIS 43464fe55dSSascha Wildner.Nm 4450fc853eSJohn Marino.Bk -words 4550fc853eSJohn Marino.Op Fl bcCdfghiRMmnrsuVz 4650fc853eSJohn Marino.Sm off 4750fc853eSJohn Marino.Op Fl k\ \& Ar field1 Op , Ar field2 4850fc853eSJohn Marino.Sm on 4950fc853eSJohn Marino.Op Fl S Ar memsize 5050fc853eSJohn Marino.Ek 517572dc55SJohn Marino.Op Fl T Ar dir 527572dc55SJohn Marino.Op Fl t Ar char 5350fc853eSJohn Marino.Op Fl o Ar output 5450fc853eSJohn Marino.Op Ar file ... 55464fe55dSSascha Wildner.Nm 5650fc853eSJohn Marino.Fl Fl help 57464fe55dSSascha Wildner.Nm 5850fc853eSJohn Marino.Fl Fl version 597572dc55SJohn Marino.Sh DESCRIPTION 607572dc55SJohn MarinoThe 617572dc55SJohn Marino.Nm 6250fc853eSJohn Marinoutility sorts text and binary files by lines. 6350fc853eSJohn MarinoA line is a record separated from the subsequent record by a 6450fc853eSJohn Marinonewline (default) or NUL \'\\0\' character (-z option). 6550fc853eSJohn MarinoA record can contain any printable or unprintable characters. 6650fc853eSJohn MarinoComparisons are based on one or more sort keys extracted from 6750fc853eSJohn Marinoeach line of input, and are performed lexicographically, 6850fc853eSJohn Marinoaccording to the current locale's collating rules and the 6950fc853eSJohn Marinospecified command-line options that can tune the actual 7050fc853eSJohn Marinosorting behavior. 717572dc55SJohn MarinoBy default, if keys are not given, 727572dc55SJohn Marino.Nm 7350fc853eSJohn Marinouses entire lines for comparison. 747572dc55SJohn Marino.Pp 7550fc853eSJohn MarinoThe command line options are as follows: 7650fc853eSJohn Marino.Bl -tag -width Ds 7750fc853eSJohn Marino.It Fl c , Fl Fl check , Fl C , Fl Fl check=silent|quiet 787572dc55SJohn MarinoCheck that the single input file is sorted. 797572dc55SJohn MarinoIf the file is not sorted, 807572dc55SJohn Marino.Nm 8150fc853eSJohn Marinoproduces the appropriate error messages and exits with code 1, 8250fc853eSJohn Marinootherwise returns 0. 8350fc853eSJohn MarinoIf 8450fc853eSJohn Marino.Fl C 8550fc853eSJohn Marinoor 8650fc853eSJohn Marino.Fl Fl check=silent 8750fc853eSJohn Marinois specified, 887572dc55SJohn Marino.Nm 897572dc55SJohn Marinoproduces no output. 9050fc853eSJohn MarinoThis is a "silent" version of 9150fc853eSJohn Marino.Fl c . 9250fc853eSJohn Marino.It Fl m , Fl Fl merge 9350fc853eSJohn MarinoMerge only. 9450fc853eSJohn MarinoThe input files are assumed to be pre-sorted. 9550fc853eSJohn MarinoIf they are not sorted the output order is undefined. 9650fc853eSJohn Marino.It Fl o Ar output , Fl Fl output Ns = Ns Ar output 9750fc853eSJohn MarinoPrint the output to the 987572dc55SJohn Marino.Ar output 9950fc853eSJohn Marinofile instead of the standard output. 100*d6ca1884SSascha WildnerThis file can be the same as one of the input files. 10150fc853eSJohn Marino.It Fl S Ar size , Fl Fl buffer-size Ns = Ns Ar size 1027572dc55SJohn MarinoUse 10350fc853eSJohn Marino.Ar size 10450fc853eSJohn Marinofor the maximum size of the memory buffer. 10550fc853eSJohn MarinoSize modifiers %,b,K,M,G,T,P,E,Z,Y can be used. 10650fc853eSJohn MarinoIf a memory limit is not explicitly specified, 10750fc853eSJohn Marino.Nm 10850fc853eSJohn Marinotakes up to about 90% of available memory. 10950fc853eSJohn MarinoIf the file size is too big to fit into the memory buffer, 11050fc853eSJohn Marinothe temporary disk files are used to perform the sorting. 11150fc853eSJohn Marino.It Fl T Ar dir , Fl Fl temporary-directory Ns = Ns Ar dir 11250fc853eSJohn MarinoStore temporary files in the directory 11350fc853eSJohn Marino.Ar dir . 11450fc853eSJohn MarinoThe default path is the value of the environment variable 11550fc853eSJohn Marino.Ev TMPDIR 11650fc853eSJohn Marinoor 11750fc853eSJohn Marino.Pa /var/tmp 1187572dc55SJohn Marinoif 1197572dc55SJohn Marino.Ev TMPDIR 1207572dc55SJohn Marinois not defined. 12150fc853eSJohn Marino.It Fl u , Fl Fl unique 12250fc853eSJohn MarinoUnique keys. 12350fc853eSJohn MarinoSuppress all lines that have a key that is equal to an already 12450fc853eSJohn Marinoprocessed one. 12550fc853eSJohn MarinoThis option, similarly to 12650fc853eSJohn Marino.Fl s , 12750fc853eSJohn Marinoimplies a stable sort. 12850fc853eSJohn MarinoIf used with 1297572dc55SJohn Marino.Fl c 13050fc853eSJohn Marinoor 13150fc853eSJohn Marino.Fl C , 13250fc853eSJohn Marino.Nm 13350fc853eSJohn Marinoalso checks that there are no lines with duplicate keys. 13450fc853eSJohn Marino.It Fl s 13550fc853eSJohn MarinoStable sort. 13650fc853eSJohn MarinoThis option maintains the original record order of records that have 13794400e62SJohn Marinoan equal key. 13850fc853eSJohn MarinoThis is a non-standard feature, but it is widely accepted and used. 13950fc853eSJohn Marino.It Fl Fl version 14050fc853eSJohn MarinoPrint the version and silently exits. 14150fc853eSJohn Marino.It Fl Fl help 14250fc853eSJohn MarinoPrint the help text and silently exits. 1437572dc55SJohn Marino.El 1447572dc55SJohn Marino.Pp 1457572dc55SJohn MarinoThe following options override the default ordering rules. 14650fc853eSJohn MarinoWhen ordering options appear independently of key field 14750fc853eSJohn Marinospecifications, they apply globally to all sort keys. 1487572dc55SJohn MarinoWhen attached to a specific key (see 1497572dc55SJohn Marino.Fl k ) , 15050fc853eSJohn Marinothe ordering options override all global ordering options for 15150fc853eSJohn Marinothe key they are attached to. 15250fc853eSJohn Marino.Bl -tag -width indent 15350fc853eSJohn Marino.It Fl b , Fl Fl ignore-leading-blanks 15450fc853eSJohn MarinoIgnore leading blank characters when comparing lines. 15550fc853eSJohn Marino.It Fl d , Fl Fl dictionary-order 15650fc853eSJohn MarinoConsider only blank spaces and alphanumeric characters in comparisons. 15750fc853eSJohn Marino.It Fl f , Fl Fl ignore-case 15850fc853eSJohn MarinoConvert all lowercase characters to their uppercase equivalent 15950fc853eSJohn Marinobefore comparison, that is, perform case-independent sorting. 16050fc853eSJohn Marino.It Fl g , Fl Fl general-numeric-sort , Fl Fl sort=general-numeric 16150fc853eSJohn MarinoSort by general numerical value. 16250fc853eSJohn MarinoAs opposed to 16350fc853eSJohn Marino.Fl n , 16450fc853eSJohn Marinothis option handles general floating points. 16550fc853eSJohn MarinoIt has a more 16650fc853eSJohn Marinopermissive format than that allowed by 1677572dc55SJohn Marino.Fl n 16850fc853eSJohn Marinobut it has a significant performance drawback. 16950fc853eSJohn Marino.It Fl h , Fl Fl human-numeric-sort , Fl Fl sort=human-numeric 17050fc853eSJohn MarinoSort by numerical value, but take into account the SI suffix, 17150fc853eSJohn Marinoif present. 17250fc853eSJohn MarinoSort first by numeric sign (negative, zero, or 17350fc853eSJohn Marinopositive); then by SI suffix (either empty, or `k' or `K', or one 17450fc853eSJohn Marinoof `MGTPEZY', in that order); and finally by numeric value. 17550fc853eSJohn MarinoThe SI suffix must immediately follow the number. 17650fc853eSJohn MarinoFor example, '12345K' sorts before '1M', because M is "larger" than K. 17750fc853eSJohn MarinoThis sort option is useful for sorting the output of a single invocation 17850fc853eSJohn Marinoof 'df' command with 17950fc853eSJohn Marino.Fl h 18050fc853eSJohn Marinoor 18150fc853eSJohn Marino.Fl H 18250fc853eSJohn Marinooptions (human-readable). 18350fc853eSJohn Marino.It Fl i , Fl Fl ignore-nonprinting 18450fc853eSJohn MarinoIgnore all non-printable characters. 18550fc853eSJohn Marino.It Fl M , Fl Fl month-sort , Fl Fl sort=month 18650fc853eSJohn MarinoSort by month abbreviations. 18750fc853eSJohn MarinoUnknown strings are considered smaller than the month names. 18850fc853eSJohn Marino.It Fl n , Fl Fl numeric-sort , Fl Fl sort=numeric 18950fc853eSJohn MarinoSort fields numerically by arithmetic value. 19050fc853eSJohn MarinoFields are supposed to have optional blanks in the beginning, an 19150fc853eSJohn Marinooptional minus sign, zero or more digits (including decimal point and 19250fc853eSJohn Marinopossible thousand separators). 19350fc853eSJohn Marino.It Fl R , Fl Fl random-sort , Fl Fl sort=random 19450fc853eSJohn MarinoSort by a random order. 19550fc853eSJohn MarinoThis is a random permutation of the inputs except that 19650fc853eSJohn Marinothe equal keys sort together. 19750fc853eSJohn MarinoIt is implemented by hashing the input keys and sorting 19850fc853eSJohn Marinothe hash values. 19950fc853eSJohn MarinoThe hash function is chosen randomly. 20050fc853eSJohn MarinoThe hash function is randomized by 20150fc853eSJohn Marino.Cm /dev/random 20250fc853eSJohn Marinocontent, or by file content if it is specified by 20350fc853eSJohn Marino.Fl Fl random-source . 20450fc853eSJohn MarinoEven if multiple sort fields are specified, 20550fc853eSJohn Marinothe same random hash function is used for all of them. 20650fc853eSJohn Marino.It Fl r , Fl Fl reverse 20750fc853eSJohn MarinoSort in reverse order. 20850fc853eSJohn Marino.It Fl V , Fl Fl version-sort 20950fc853eSJohn MarinoSort version numbers. 21050fc853eSJohn MarinoThe input lines are treated as file names in form 21150fc853eSJohn MarinoPREFIX VERSION SUFFIX, where SUFFIX matches the regular expression 21250fc853eSJohn Marino"(\.([A-Za-z~][A-Za-z0-9~]*)?)*". 21350fc853eSJohn MarinoThe files are compared by their prefixes and versions (leading 21450fc853eSJohn Marinozeros are ignored in version numbers, see example below). 21550fc853eSJohn MarinoIf an input string does not match the pattern, then it is compared 21650fc853eSJohn Marinousing the byte compare function. 21750fc853eSJohn MarinoAll string comparisons are performed in C locale, the locale 21850fc853eSJohn Marinoenvironment setting is ignored. 21950fc853eSJohn Marino.Bl -tag -width indent 22050fc853eSJohn Marino.It Example: 22150fc853eSJohn Marino.It $ ls sort* | sort -V 22250fc853eSJohn Marino.It sort-1.022.tgz 22350fc853eSJohn Marino.It sort-1.23.tgz 22450fc853eSJohn Marino.It sort-1.23.1.tgz 22550fc853eSJohn Marino.It sort-1.024.tgz 22650fc853eSJohn Marino.It sort-1.024.003. 22750fc853eSJohn Marino.It sort-1.024.003.tgz 22850fc853eSJohn Marino.It sort-1.024.07.tgz 22950fc853eSJohn Marino.It sort-1.024.009.tgz 23050fc853eSJohn Marino.El 2317572dc55SJohn Marino.El 2327572dc55SJohn Marino.Pp 2337572dc55SJohn MarinoThe treatment of field separators can be altered using these options: 23450fc853eSJohn Marino.Bl -tag -width indent 23550fc853eSJohn Marino.It Fl b , Fl Fl ignore-leading-blanks 23650fc853eSJohn MarinoIgnore leading blank space when determining the start 23750fc853eSJohn Marinoand end of a restricted sort key (see 238464fe55dSSascha Wildner.Fl k ) . 23950fc853eSJohn MarinoIf 2407572dc55SJohn Marino.Fl b 24150fc853eSJohn Marinois specified before the first 24250fc853eSJohn Marino.Fl k 24350fc853eSJohn Marinooption, it applies globally to all key specifications. 24450fc853eSJohn MarinoOtherwise, 24550fc853eSJohn Marino.Fl b 24650fc853eSJohn Marinocan be attached independently to each 2477572dc55SJohn Marino.Ar field 24850fc853eSJohn Marinoargument of the key specifications. 24950fc853eSJohn Marino.Fl b . 25050fc853eSJohn Marino.It Xo 25150fc853eSJohn Marino.Fl k Ar field1 Ns Op , Ns Ar field2 , 25250fc853eSJohn Marino.Fl Fl key Ns = Ns Ar field1 Ns Op , Ns Ar field2 25350fc853eSJohn Marino.Xc 25450fc853eSJohn MarinoDefine a restricted sort key that has the starting position 25550fc853eSJohn Marino.Ar field1 , 25650fc853eSJohn Marinoand optional ending position 25750fc853eSJohn Marino.Ar field2 25850fc853eSJohn Marinoof a key field. 25950fc853eSJohn MarinoThe 2607572dc55SJohn Marino.Fl k 26150fc853eSJohn Marinooption may be specified multiple times, 26250fc853eSJohn Marinoin which case subsequent keys are compared when earlier keys compare equal. 26350fc853eSJohn MarinoThe 26450fc853eSJohn Marino.Fl k 26550fc853eSJohn Marinooption replaces the obsolete options 26650fc853eSJohn Marino.Cm \(pl Ns Ar pos1 26750fc853eSJohn Marinoand 26850fc853eSJohn Marino.Fl Ns Ar pos2 , 26950fc853eSJohn Marinobut the old notation is also supported. 27050fc853eSJohn Marino.It Fl t Ar char , Fl Fl field-separator Ns = Ns Ar char 27150fc853eSJohn MarinoUse 2727572dc55SJohn Marino.Ar char 27350fc853eSJohn Marinoas a field separator character. 2747572dc55SJohn MarinoThe initial 2757572dc55SJohn Marino.Ar char 27650fc853eSJohn Marinois not considered to be part of a field when determining key offsets. 2777572dc55SJohn MarinoEach occurrence of 2787572dc55SJohn Marino.Ar char 2797572dc55SJohn Marinois significant (for example, 2807572dc55SJohn Marino.Dq Ar charchar 2817572dc55SJohn Marinodelimits an empty field). 2827572dc55SJohn MarinoIf 2837572dc55SJohn Marino.Fl t 2847572dc55SJohn Marinois not specified, the default field separator is a sequence of 28550fc853eSJohn Marinoblank space characters, and consecutive blank spaces do 2867572dc55SJohn Marino.Em not 28750fc853eSJohn Marinodelimit an empty field, however, the initial blank space 2887572dc55SJohn Marino.Em is 2897572dc55SJohn Marinoconsidered part of a field when determining key offsets. 29050fc853eSJohn MarinoTo use NUL as field separator, use 29150fc853eSJohn Marino.Fl t 29250fc853eSJohn Marino\'\\0\'. 29350fc853eSJohn Marino.It Fl z , Fl Fl zero-terminated 29450fc853eSJohn MarinoUse NUL as record separator. 29550fc853eSJohn MarinoBy default, records in the files are supposed to be separated by 29650fc853eSJohn Marinothe newline characters. 29750fc853eSJohn MarinoWith this option, NUL (\'\\0\') is used as a record separator character. 29850fc853eSJohn Marino.El 29950fc853eSJohn Marino.Pp 30050fc853eSJohn MarinoOther options: 30150fc853eSJohn Marino.Bl -tag -width indent 30250fc853eSJohn Marino.It Fl Fl batch-size Ns = Ns Ar num 30350fc853eSJohn MarinoSpecify maximum number of files that can be opened by 30450fc853eSJohn Marino.Nm 30550fc853eSJohn Marinoat once. 30650fc853eSJohn MarinoThis option affects behavior when having many input files or using 30750fc853eSJohn Marinotemporary files. 30850fc853eSJohn MarinoThe default value is 16. 30950fc853eSJohn Marino.It Fl Fl compress-program Ns = Ns Ar PROGRAM 31050fc853eSJohn MarinoUse PROGRAM to compress temporary files. 31150fc853eSJohn MarinoPROGRAM must compress standard input to standard output, when called 31250fc853eSJohn Marinowithout arguments. 31350fc853eSJohn MarinoWhen called with argument 31450fc853eSJohn Marino.Fl d 31550fc853eSJohn Marinoit must decompress standard input to standard output. 31650fc853eSJohn MarinoIf PROGRAM fails, 31750fc853eSJohn Marino.Nm 31850fc853eSJohn Marinomust exit with error. 31950fc853eSJohn MarinoAn example of PROGRAM that can be used here is bzip2. 32050fc853eSJohn Marino.It Fl Fl random-source Ns = Ns Ar filename 32150fc853eSJohn MarinoIn random sort, the file content is used as the source of the 'seed' data 32250fc853eSJohn Marinofor the hash function choice. 32350fc853eSJohn MarinoTwo invocations of random sort with the same seed data will use 32450fc853eSJohn Marinothe same hash function and will produce the same result if the input is 32550fc853eSJohn Marinoalso identical. 32650fc853eSJohn MarinoBy default, file 32750fc853eSJohn Marino.Cm /dev/random 32850fc853eSJohn Marinois used. 32950fc853eSJohn Marino.It Fl Fl debug 33050fc853eSJohn MarinoPrint some extra information about the sorting process to the 33150fc853eSJohn Marinostandard output. 33250fc853eSJohn Marino.It Fl Fl parallel 33350fc853eSJohn MarinoSet the maximum number of execution threads. 33450fc853eSJohn MarinoDefault number equals to the number of CPUs. 33550fc853eSJohn Marino.It Fl Fl files0-from Ns = Ns Ar filename 33650fc853eSJohn MarinoTake the input file list from the file 33750fc853eSJohn Marino.Ar filename . 33850fc853eSJohn MarinoThe file names must be separated by NUL 33950fc853eSJohn Marino(like the output produced by the command "find ... -print0"). 34050fc853eSJohn Marino.It Fl Fl radixsort 34150fc853eSJohn MarinoTry to use radix sort, if the sort specifications allow. 34250fc853eSJohn MarinoThe radix sort can only be used for trivial locales (C and POSIX), 34350fc853eSJohn Marinoand it cannot be used for numeric or month sort. 34450fc853eSJohn MarinoRadix sort is very fast and stable. 34550fc853eSJohn Marino.It Fl Fl mergesort 34650fc853eSJohn MarinoUse mergesort. 34750fc853eSJohn MarinoThis is a universal algorithm that can always be used, 34850fc853eSJohn Marinobut it is not always the fastest. 34950fc853eSJohn Marino.It Fl Fl qsort 35050fc853eSJohn MarinoTry to use quick sort, if the sort specifications allow. 35150fc853eSJohn MarinoThis sort algorithm cannot be used with 35250fc853eSJohn Marino.Fl u 3537572dc55SJohn Marinoand 35450fc853eSJohn Marino.Fl s . 35550fc853eSJohn Marino.It Fl Fl heapsort 35650fc853eSJohn MarinoTry to use heap sort, if the sort specifications allow. 35750fc853eSJohn MarinoThis sort algorithm cannot be used with 35850fc853eSJohn Marino.Fl u 35950fc853eSJohn Marinoand 36050fc853eSJohn Marino.Fl s . 36150fc853eSJohn Marino.It Fl Fl mmap 36250fc853eSJohn MarinoTry to use file memory mapping system call. 36350fc853eSJohn MarinoIt may increase speed in some cases. 3647572dc55SJohn Marino.El 3657572dc55SJohn Marino.Pp 3667572dc55SJohn MarinoThe following operands are available: 36750fc853eSJohn Marino.Bl -tag -width indent 3687572dc55SJohn Marino.It Ar file 3697572dc55SJohn MarinoThe pathname of a file to be sorted, merged, or checked. 3707572dc55SJohn MarinoIf no 3717572dc55SJohn Marino.Ar file 37250fc853eSJohn Marinooperands are specified, or if a 3737572dc55SJohn Marino.Ar file 3747572dc55SJohn Marinooperand is 3757572dc55SJohn Marino.Fl , 3767572dc55SJohn Marinothe standard input is used. 3777572dc55SJohn Marino.El 3787572dc55SJohn Marino.Pp 37950fc853eSJohn MarinoA field is defined as a maximal sequence of characters other than the 38050fc853eSJohn Marinofield separator and record separator (newline by default). 38150fc853eSJohn MarinoInitial blank spaces are included in the field unless 38250fc853eSJohn Marino.Fl b 38350fc853eSJohn Marinohas been specified; 38450fc853eSJohn Marinothe first blank space of a sequence of blank spaces acts as the field 38550fc853eSJohn Marinoseparator and is included in the field (unless 38650fc853eSJohn Marino.Fl t 38750fc853eSJohn Marinois specified). 38850fc853eSJohn MarinoFor example, all blank spaces at the beginning of a line are 38950fc853eSJohn Marinoconsidered to be part of the first field. 3907572dc55SJohn Marino.Pp 39150fc853eSJohn MarinoFields are specified by the 39250fc853eSJohn Marino.Sm off 39350fc853eSJohn Marino.Fl k\ \& Ar field1 Op , Ar field2 39450fc853eSJohn Marino.Sm on 39550fc853eSJohn Marinocommand-line option. 39650fc853eSJohn MarinoIf 3977572dc55SJohn Marino.Ar field2 39850fc853eSJohn Marinois missing, the end of the key defaults to the end of the line. 3997572dc55SJohn Marino.Pp 4007572dc55SJohn MarinoThe arguments 4017572dc55SJohn Marino.Ar field1 4027572dc55SJohn Marinoand 4037572dc55SJohn Marino.Ar field2 4047572dc55SJohn Marinohave the form 40550fc853eSJohn Marino.Em m.n 40650fc853eSJohn Marino.Em (m,n > 0) 40750fc853eSJohn Marinoand can be followed by one or more of the modifiers 4087572dc55SJohn Marino.Cm b , d , f , i , 40950fc853eSJohn Marino.Cm n , g , M 4107572dc55SJohn Marinoand 4117572dc55SJohn Marino.Cm r , 4127572dc55SJohn Marinowhich correspond to the options discussed above. 41350fc853eSJohn MarinoWhen 41450fc853eSJohn Marino.Cm b 41550fc853eSJohn Marinois specified it applies only to 41650fc853eSJohn Marino.Ar field1 41750fc853eSJohn Marinoor 41850fc853eSJohn Marino.Ar field2 41950fc853eSJohn Marinowhere it is specified while the rest of the modifiers 42050fc853eSJohn Marinoapply to the whole key field regardless if they are 42150fc853eSJohn Marinospecified only with 42250fc853eSJohn Marino.Ar field1 42350fc853eSJohn Marinoor 42450fc853eSJohn Marino.Ar field2 42550fc853eSJohn Marinoor both. 4267572dc55SJohn MarinoA 4277572dc55SJohn Marino.Ar field1 4287572dc55SJohn Marinoposition specified by 42950fc853eSJohn Marino.Em m.n 4307572dc55SJohn Marinois interpreted as the 43150fc853eSJohn Marino.Em n Ns th 43250fc853eSJohn Marinocharacter from the beginning of the 43350fc853eSJohn Marino.Em m Ns th 4347572dc55SJohn Marinofield. 4357572dc55SJohn MarinoA missing 43650fc853eSJohn Marino.Em \&.n 4377572dc55SJohn Marinoin 4387572dc55SJohn Marino.Ar field1 4397572dc55SJohn Marinomeans 4407572dc55SJohn Marino.Ql \&.1 , 4417572dc55SJohn Marinoindicating the first character of the 44250fc853eSJohn Marino.Em m Ns th 4437572dc55SJohn Marinofield; if the 4447572dc55SJohn Marino.Fl b 4457572dc55SJohn Marinooption is in effect, 44650fc853eSJohn Marino.Em n 4477572dc55SJohn Marinois counted from the first non-blank character in the 44850fc853eSJohn Marino.Em m Ns th 4497572dc55SJohn Marinofield; 45050fc853eSJohn Marino.Em m Ns \&.1b 4517572dc55SJohn Marinorefers to the first non-blank character in the 45250fc853eSJohn Marino.Em m Ns th 4537572dc55SJohn Marinofield. 45450fc853eSJohn Marino.No 1\&. Ns Em n 45550fc853eSJohn Marinorefers to the 45650fc853eSJohn Marino.Em n Ns th 45750fc853eSJohn Marinocharacter from the beginning of the line; 45850fc853eSJohn Marinoif 45950fc853eSJohn Marino.Em n 46050fc853eSJohn Marinois greater than the length of the line, the field is taken to be empty. 46150fc853eSJohn Marino.Pp 46250fc853eSJohn Marino.Em n Ns th 46350fc853eSJohn Marinopositions are always counted from the field beginning, even if the field 46450fc853eSJohn Marinois shorter than the number of specified positions. 46550fc853eSJohn MarinoThus, the key can really start from a position in a subsequent field. 4667572dc55SJohn Marino.Pp 4677572dc55SJohn MarinoA 4687572dc55SJohn Marino.Ar field2 4697572dc55SJohn Marinoposition specified by 47050fc853eSJohn Marino.Em m.n 47150fc853eSJohn Marinois interpreted as the 47250fc853eSJohn Marino.Em n Ns th 47350fc853eSJohn Marinocharacter (including separators) from the beginning of the 47450fc853eSJohn Marino.Em m Ns th 4757572dc55SJohn Marinofield. 4767572dc55SJohn MarinoA missing 47750fc853eSJohn Marino.Em \&.n 4787572dc55SJohn Marinoindicates the last character of the 47950fc853eSJohn Marino.Em m Ns th 4807572dc55SJohn Marinofield; 48150fc853eSJohn Marino.Em m 4827572dc55SJohn Marino= \&0 4837572dc55SJohn Marinodesignates the end of a line. 4847572dc55SJohn MarinoThus the option 48550fc853eSJohn Marino.Fl k Ar v.x,w.y 48650fc853eSJohn Marinois synonymous with the obsolete option 48750fc853eSJohn Marino.Cm \(pl Ns Ar v-\&1.x-\&1 48850fc853eSJohn Marino.Fl Ns Ar w-\&1.y ; 4897572dc55SJohn Marinowhen 49050fc853eSJohn Marino.Em y 4917572dc55SJohn Marinois omitted, 49250fc853eSJohn Marino.Fl k Ar v.x,w 4937572dc55SJohn Marinois synonymous with 49450fc853eSJohn Marino.Cm \(pl Ns Ar v-\&1.x-\&1 49550fc853eSJohn Marino.Fl Ns Ar w\&.0 . 49650fc853eSJohn MarinoThe obsolete 4977572dc55SJohn Marino.Cm \(pl Ns Ar pos1 4987572dc55SJohn Marino.Fl Ns Ar pos2 4997572dc55SJohn Marinooption is still supported, except for 50050fc853eSJohn Marino.Fl Ns Ar w\&.0b , 5017572dc55SJohn Marinowhich has no 5027572dc55SJohn Marino.Fl k 5037572dc55SJohn Marinoequivalent. 5047572dc55SJohn Marino.Sh ENVIRONMENT 50550fc853eSJohn Marino.Bl -tag -width Fl 50650fc853eSJohn Marino.It Ev LC_COLLATE 50750fc853eSJohn MarinoLocale settings to be used to determine the collation for 50850fc853eSJohn Marinosorting records. 50950fc853eSJohn Marino.It Ev LC_CTYPE 51050fc853eSJohn MarinoLocale settings to be used to case conversion and classification 51150fc853eSJohn Marinoof characters, that is, which characters are considered 51250fc853eSJohn Marinowhitespaces, etc. 51350fc853eSJohn Marino.It Ev LC_MESSAGES 51450fc853eSJohn MarinoLocale settings that determine the language of output messages 51550fc853eSJohn Marinothat 5167572dc55SJohn Marino.Nm 51750fc853eSJohn Marinoprints out. 51850fc853eSJohn Marino.It Ev LC_NUMERIC 51950fc853eSJohn MarinoLocale settings that determine the number format used in numeric sort. 52050fc853eSJohn Marino.It Ev LC_TIME 52150fc853eSJohn MarinoLocale settings that determine the month format used in month sort. 52250fc853eSJohn Marino.It Ev LC_ALL 52350fc853eSJohn MarinoLocale settings that override all of the above locale settings. 52450fc853eSJohn MarinoThis environment variable can be used to set all these settings 52550fc853eSJohn Marinoto the same value at once. 52650fc853eSJohn Marino.It Ev LANG 52750fc853eSJohn MarinoUsed as a last resort to determine different kinds of locale-specific 52850fc853eSJohn Marinobehavior if neither the respective environment variable, nor 52950fc853eSJohn Marino.Ev LC_ALL 53050fc853eSJohn Marinoare set. 531464fe55dSSascha Wildner.\"%%NLS%%.It Ev NLSPATH 532464fe55dSSascha Wildner.\"%%NLS%%Path to NLS catalogs. 53350fc853eSJohn Marino.It Ev TMPDIR 53450fc853eSJohn MarinoPath to the directory in which temporary files will be stored. 53550fc853eSJohn MarinoNote that 5367572dc55SJohn Marino.Ev TMPDIR 53750fc853eSJohn Marinomay be overridden by the 53850fc853eSJohn Marino.Fl T 53950fc853eSJohn Marinooption. 54050fc853eSJohn Marino.It Ev GNUSORT_NUMERIC_COMPATIBILITY 54150fc853eSJohn MarinoIf defined 54250fc853eSJohn Marino.Fl t 54350fc853eSJohn Marinowill not override the locale numeric symbols, that is, thousand 54450fc853eSJohn Marinoseparators and decimal separators. 54550fc853eSJohn MarinoBy default, if we specify 54650fc853eSJohn Marino.Fl t 54750fc853eSJohn Marinowith the same symbol as the thousand separator or decimal point, 54850fc853eSJohn Marinothe symbol will be treated as the field separator. 54950fc853eSJohn MarinoOlder behavior was less definite; the symbol was treated as both field 55050fc853eSJohn Marinoseparator and numeric separator, simultaneously. 55150fc853eSJohn MarinoThis environment variable enables the old behavior. 5527572dc55SJohn Marino.El 5537572dc55SJohn Marino.Sh FILES 55450fc853eSJohn Marino.Bl -tag -width Pa -compact 55550fc853eSJohn Marino.It Pa /var/tmp/.bsdsort.PID.* 55650fc853eSJohn MarinoTemporary files. 55750fc853eSJohn Marino.It Pa /dev/random 55850fc853eSJohn MarinoDefault seed file for the random sort. 5597572dc55SJohn Marino.El 5607572dc55SJohn Marino.Sh EXIT STATUS 56150fc853eSJohn MarinoThe 56250fc853eSJohn Marino.Nm 56350fc853eSJohn Marinoutility shall exit with one of the following values: 56450fc853eSJohn Marino.Pp 5657572dc55SJohn Marino.Bl -tag -width flag -compact 5667572dc55SJohn Marino.It 0 56750fc853eSJohn MarinoSuccessfully sorted the input files or if used with 56850fc853eSJohn Marino.Fl c 56950fc853eSJohn Marinoor 57050fc853eSJohn Marino.Fl C , 57150fc853eSJohn Marinothe input file already met the sorting criteria. 5727572dc55SJohn Marino.It 1 5737572dc55SJohn MarinoOn disorder (or non-uniqueness) with the 5747572dc55SJohn Marino.Fl c 57550fc853eSJohn Marinoor 57650fc853eSJohn Marino.Fl C 57750fc853eSJohn Marinooptions. 5787572dc55SJohn Marino.It 2 5797572dc55SJohn MarinoAn error occurred. 5807572dc55SJohn Marino.El 5817572dc55SJohn Marino.Sh SEE ALSO 5827572dc55SJohn Marino.Xr comm 1 , 5837572dc55SJohn Marino.Xr join 1 , 58450fc853eSJohn Marino.Xr uniq 1 58550fc853eSJohn Marino.Sh STANDARDS 58650fc853eSJohn MarinoThe 58750fc853eSJohn Marino.Nm 58850fc853eSJohn Marinoutility is compliant with the 58950fc853eSJohn Marino.St -p1003.1-2008 59050fc853eSJohn Marinospecification. 59150fc853eSJohn Marino.Pp 59250fc853eSJohn MarinoThe flags 59350fc853eSJohn Marino.Op Fl ghRMSsTVz 59450fc853eSJohn Marinoare extensions to the POSIX specification. 59550fc853eSJohn Marino.Pp 59650fc853eSJohn MarinoAll long options are extensions to the specification, some of them are 59750fc853eSJohn Marinoprovided for compatibility with GNU versions and some of them are 59850fc853eSJohn Marinoown extensions. 59950fc853eSJohn Marino.Pp 60050fc853eSJohn MarinoThe old key notations 60150fc853eSJohn Marino.Cm \(pl Ns Ar pos1 60250fc853eSJohn Marinoand 60350fc853eSJohn Marino.Fl Ns Ar pos2 60450fc853eSJohn Marinocome from older versions of 60550fc853eSJohn Marino.Nm 60650fc853eSJohn Marinoand are still supported but their use is highly discouraged. 6077572dc55SJohn Marino.Sh HISTORY 6087572dc55SJohn MarinoA 6097572dc55SJohn Marino.Nm 61050fc853eSJohn Marinocommand first appeared in 61150fc853eSJohn Marino.At v3 . 61250fc853eSJohn Marino.Sh AUTHORS 61350fc853eSJohn Marino.An Gabor Kovesdan Aq Mt gabor@FreeBSD.org , 61450fc853eSJohn Marino.Pp 61550fc853eSJohn Marino.An Oleg Moskalenko Aq Mt mom040267@gmail.com 6167572dc55SJohn Marino.Sh NOTES 61750fc853eSJohn MarinoThis implementation of 6187572dc55SJohn Marino.Nm 6197572dc55SJohn Marinohas no limits on input line length (other than imposed by available 6207572dc55SJohn Marinomemory) or any restrictions on bytes allowed within lines. 6217572dc55SJohn Marino.Pp 62250fc853eSJohn MarinoThe performance depends highly on locale settings, 62350fc853eSJohn Marinoefficient choice of sort keys and key complexity. 62450fc853eSJohn MarinoThe fastest sort is with locale C, on whole lines, 62550fc853eSJohn Marinowith option 62650fc853eSJohn Marino.Fl s . 62750fc853eSJohn MarinoIn general, locale C is the fastest, then single-byte 62850fc853eSJohn Marinolocales follow and multi-byte locales as the slowest but 62950fc853eSJohn Marinothe correct collation order is always respected. 63050fc853eSJohn MarinoAs for the key specification, the simpler to process the 63150fc853eSJohn Marinolines the faster the search will be. 6327572dc55SJohn Marino.Pp 63350fc853eSJohn MarinoWhen sorting by arithmetic value, using 63450fc853eSJohn Marino.Fl n 63550fc853eSJohn Marinoresults in much better performance than 63650fc853eSJohn Marino.Fl g 63750fc853eSJohn Marinoso its use is encouraged 63850fc853eSJohn Marinowhenever possible. 639