xref: /freebsd/usr.bin/sort/sort.1.in (revision f79477ebd57d7b0e69654281387ba5db8950ebd8)
1*f79477ebSPedro F. Giffuni.\"	$OpenBSD: sort.1,v 1.45 2015/03/19 13:51:10 jmc Exp $
2c66bbc91SGabor Kovesdan.\"	$FreeBSD$
3c66bbc91SGabor Kovesdan.\"
4c66bbc91SGabor Kovesdan.\" Copyright (c) 1991, 1993
5c66bbc91SGabor Kovesdan.\"	The Regents of the University of California.  All rights reserved.
6c66bbc91SGabor Kovesdan.\"
7c66bbc91SGabor Kovesdan.\" This code is derived from software contributed to Berkeley by
8c66bbc91SGabor Kovesdan.\" the Institute of Electrical and Electronics Engineers, Inc.
9c66bbc91SGabor Kovesdan.\"
10c66bbc91SGabor Kovesdan.\" Redistribution and use in source and binary forms, with or without
11c66bbc91SGabor Kovesdan.\" modification, are permitted provided that the following conditions
12c66bbc91SGabor Kovesdan.\" are met:
13c66bbc91SGabor Kovesdan.\" 1. Redistributions of source code must retain the above copyright
14c66bbc91SGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer.
15c66bbc91SGabor Kovesdan.\" 2. Redistributions in binary form must reproduce the above copyright
16c66bbc91SGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer in the
17c66bbc91SGabor Kovesdan.\"    documentation and/or other materials provided with the distribution.
18c66bbc91SGabor Kovesdan.\" 3. Neither the name of the University nor the names of its contributors
19c66bbc91SGabor Kovesdan.\"    may be used to endorse or promote products derived from this software
20c66bbc91SGabor Kovesdan.\"    without specific prior written permission.
21c66bbc91SGabor Kovesdan.\"
22c66bbc91SGabor Kovesdan.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23c66bbc91SGabor Kovesdan.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24c66bbc91SGabor Kovesdan.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25c66bbc91SGabor Kovesdan.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26c66bbc91SGabor Kovesdan.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27c66bbc91SGabor Kovesdan.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28c66bbc91SGabor Kovesdan.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29c66bbc91SGabor Kovesdan.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30c66bbc91SGabor Kovesdan.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31c66bbc91SGabor Kovesdan.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32c66bbc91SGabor Kovesdan.\" SUCH DAMAGE.
33c66bbc91SGabor Kovesdan.\"
34c66bbc91SGabor Kovesdan.\"     @(#)sort.1	8.1 (Berkeley) 6/6/93
35c66bbc91SGabor Kovesdan.\"
36*f79477ebSPedro F. Giffuni.Dd March 19 2015
37c66bbc91SGabor Kovesdan.Dt SORT 1
38c66bbc91SGabor Kovesdan.Os
39c66bbc91SGabor Kovesdan.Sh NAME
40c66bbc91SGabor Kovesdan.Nm sort
41c66bbc91SGabor Kovesdan.Nd sort or merge records (lines) of text and binary files
42c66bbc91SGabor Kovesdan.Sh SYNOPSIS
43c66bbc91SGabor Kovesdan.Nm sort
44c66bbc91SGabor Kovesdan.Bk -words
45c66bbc91SGabor Kovesdan.Op Fl bcCdfghiRMmnrsuVz
46c66bbc91SGabor Kovesdan.Sm off
47c66bbc91SGabor Kovesdan.Op Fl k\ \& Ar field1 Op , Ar field2
48c66bbc91SGabor Kovesdan.Sm on
49c66bbc91SGabor Kovesdan.Op Fl S Ar memsize
50c66bbc91SGabor Kovesdan.Ek
51c66bbc91SGabor Kovesdan.Op Fl T Ar dir
52c66bbc91SGabor Kovesdan.Op Fl t Ar char
53c66bbc91SGabor Kovesdan.Op Fl o Ar output
54c66bbc91SGabor Kovesdan.Op Ar file ...
55c66bbc91SGabor Kovesdan.Nm sort
56c66bbc91SGabor Kovesdan.Fl Fl help
57c66bbc91SGabor Kovesdan.Nm sort
58c66bbc91SGabor Kovesdan.Fl Fl version
59c66bbc91SGabor Kovesdan.Sh DESCRIPTION
60c66bbc91SGabor KovesdanThe
61c66bbc91SGabor Kovesdan.Nm
62c66bbc91SGabor Kovesdanutility sorts text and binary files by lines.
63c66bbc91SGabor KovesdanA line is a record separated from the subsequent record by a
64c66bbc91SGabor Kovesdannewline (default) or NUL \'\\0\' character (-z option).
65c66bbc91SGabor KovesdanA record can contain any printable or unprintable characters.
66c66bbc91SGabor KovesdanComparisons are based on one or more sort keys extracted from
67c66bbc91SGabor Kovesdaneach line of input, and are performed lexicographically,
68c66bbc91SGabor Kovesdanaccording to the current locale's collating rules and the
69c66bbc91SGabor Kovesdanspecified command-line options that can tune the actual
70c66bbc91SGabor Kovesdansorting behavior.
71c66bbc91SGabor KovesdanBy default, if keys are not given,
72c66bbc91SGabor Kovesdan.Nm
73c66bbc91SGabor Kovesdanuses entire lines for comparison.
74c66bbc91SGabor Kovesdan.Pp
75c66bbc91SGabor KovesdanThe command line options are as follows:
76c66bbc91SGabor Kovesdan.Bl -tag -width Ds
77c66bbc91SGabor Kovesdan.It Fl c, Fl Fl check, Fl C, Fl Fl check=silent|quiet
78c66bbc91SGabor KovesdanCheck that the single input file is sorted.
79c66bbc91SGabor KovesdanIf the file is not sorted,
80c66bbc91SGabor Kovesdan.Nm
81c66bbc91SGabor Kovesdanproduces the appropriate error messages and exits with code 1,
82c66bbc91SGabor Kovesdanotherwise returns 0.
83c66bbc91SGabor KovesdanIf
84c66bbc91SGabor Kovesdan.Fl C
85c66bbc91SGabor Kovesdanor
86c66bbc91SGabor Kovesdan.Fl Fl check=silent
87c66bbc91SGabor Kovesdanis specified,
88c66bbc91SGabor Kovesdan.Nm
89c66bbc91SGabor Kovesdanproduces no output.
90c66bbc91SGabor KovesdanThis is a "silent" version of
91c66bbc91SGabor Kovesdan.Fl c.
92c66bbc91SGabor Kovesdan.It Fl m , Fl Fl merge
93c66bbc91SGabor KovesdanMerge only.
94c66bbc91SGabor KovesdanThe input files are assumed to be pre-sorted.
95c66bbc91SGabor KovesdanIf they are not sorted the output order is undefined.
96c66bbc91SGabor Kovesdan.It Fl o Ar output , Fl Fl output Ns = Ns Ar output
97c66bbc91SGabor KovesdanPrint the output to the
98c66bbc91SGabor Kovesdan.Ar output
99c66bbc91SGabor Kovesdanfile instead of the standard output.
100c66bbc91SGabor Kovesdan.It Fl S Ar size, Fl Fl buffer-size Ns = Ns Ar size
101c66bbc91SGabor KovesdanUse
102c66bbc91SGabor Kovesdan.Ar size
103c66bbc91SGabor Kovesdanfor the maximum size of the memory buffer.
104c66bbc91SGabor KovesdanSize modifiers %,b,K,M,G,T,P,E,Z,Y can be used.
105c66bbc91SGabor KovesdanIf a memory limit is not explicitly specified,
106c66bbc91SGabor Kovesdan.Nm
107c66bbc91SGabor Kovesdantakes up to about 90% of available memory.
108c66bbc91SGabor KovesdanIf the file size is too big to fit into the memory buffer,
109c66bbc91SGabor Kovesdanthe temporary disk files are used to perform the sorting.
110c66bbc91SGabor Kovesdan.It Fl T Ar dir , Fl Fl temporary-directory Ns = Ns Ar dir
111c66bbc91SGabor KovesdanStore temporary files in the directory
112c66bbc91SGabor Kovesdan.Ar dir .
113c66bbc91SGabor KovesdanThe default path is the value of the environment variable
114c66bbc91SGabor Kovesdan.Ev TMPDIR
115c66bbc91SGabor Kovesdanor
116c66bbc91SGabor Kovesdan.Pa /var/tmp
117c66bbc91SGabor Kovesdanif
118c66bbc91SGabor Kovesdan.Ev TMPDIR
119c66bbc91SGabor Kovesdanis not defined.
120c66bbc91SGabor Kovesdan.It Fl u , Fl Fl unique
121c66bbc91SGabor KovesdanUnique keys.
122c66bbc91SGabor KovesdanSuppress all lines that have a key that is equal to an already
123c66bbc91SGabor Kovesdanprocessed one.
124c66bbc91SGabor KovesdanThis option, similarly to
125c66bbc91SGabor Kovesdan.Fl s ,
126c66bbc91SGabor Kovesdanimplies a stable sort.
127c66bbc91SGabor KovesdanIf used with
128c66bbc91SGabor Kovesdan.Fl c
129c66bbc91SGabor Kovesdanor
130c66bbc91SGabor Kovesdan.Fl C ,
131c66bbc91SGabor Kovesdan.Nm
132c66bbc91SGabor Kovesdanalso checks that there are no lines with duplicate keys.
133c66bbc91SGabor Kovesdan.It Fl s
134c66bbc91SGabor KovesdanStable sort.
135c66bbc91SGabor KovesdanThis option maintains the original record order of records that have
136c66bbc91SGabor Kovesdanand equal key.
137c66bbc91SGabor KovesdanThis is a non-standard feature, but it is widely accepted and used.
138c66bbc91SGabor Kovesdan.It Fl Fl version
139c66bbc91SGabor KovesdanPrint the version and silently exits.
140c66bbc91SGabor Kovesdan.It Fl Fl help
141c66bbc91SGabor KovesdanPrint the help text and silently exits.
142c66bbc91SGabor Kovesdan.El
143c66bbc91SGabor Kovesdan.Pp
144c66bbc91SGabor KovesdanThe following options override the default ordering rules.
145c66bbc91SGabor KovesdanWhen ordering options appear independently of key field
146c66bbc91SGabor Kovesdanspecifications, they apply globally to all sort keys.
147c66bbc91SGabor KovesdanWhen attached to a specific key (see
148c66bbc91SGabor Kovesdan.Fl k ) ,
149c66bbc91SGabor Kovesdanthe ordering options override all global ordering options for
150459d6434SBryan Drewerythe key they are attached to.
151c66bbc91SGabor Kovesdan.Bl -tag -width indent
152c66bbc91SGabor Kovesdan.It Fl b, Fl Fl ignore-leading-blanks
153c66bbc91SGabor KovesdanIgnore leading blank characters when comparing lines.
154c66bbc91SGabor Kovesdan.It Fl d , Fl Fl dictionary-order
155c66bbc91SGabor KovesdanConsider only blank spaces and alphanumeric characters in comparisons.
156c66bbc91SGabor Kovesdan.It Fl f , Fl Fl ignore-case
157c66bbc91SGabor KovesdanConvert all lowercase characters to their uppercase equivalent
158c66bbc91SGabor Kovesdanbefore comparison, that is, perform case-independent sorting.
159c66bbc91SGabor Kovesdan.It Fl g, Fl Fl general-numeric-sort, Fl Fl sort=general-numeric
160c66bbc91SGabor KovesdanSort by general numerical value.
161c66bbc91SGabor KovesdanAs opposed to
162c66bbc91SGabor Kovesdan.Fl n ,
163*f79477ebSPedro F. Giffunithis option handles general floating points.
164*f79477ebSPedro F. GiffuniIt has a more
165*f79477ebSPedro F. Giffunipermissive format than that allowed by
166*f79477ebSPedro F. Giffuni.Fl n
167c66bbc91SGabor Kovesdanbut it has a significant performance drawback.
168c66bbc91SGabor Kovesdan.It Fl h, Fl Fl human-numeric-sort, Fl Fl sort=human-numeric
169c66bbc91SGabor KovesdanSort by numerical value, but take into account the SI suffix,
170c66bbc91SGabor Kovesdanif present.
171c66bbc91SGabor KovesdanSort first by numeric sign (negative, zero, or
172c66bbc91SGabor Kovesdanpositive); then by SI suffix (either empty, or `k' or `K', or one
173c66bbc91SGabor Kovesdanof `MGTPEZY', in that order); and finally by numeric value.
174c66bbc91SGabor KovesdanThe SI suffix must immediately follow the number.
175c66bbc91SGabor KovesdanFor example, '12345K' sorts before '1M', because M is "larger" than K.
176c66bbc91SGabor KovesdanThis sort option is useful for sorting the output of a single invocation
177c66bbc91SGabor Kovesdanof 'df' command with
178c66bbc91SGabor Kovesdan.Fl h
179c66bbc91SGabor Kovesdanor
180c66bbc91SGabor Kovesdan.Fl H
181c66bbc91SGabor Kovesdanoptions (human-readable).
182c66bbc91SGabor Kovesdan.It Fl i , Fl Fl ignore-nonprinting
183c66bbc91SGabor KovesdanIgnore all non-printable characters.
184c66bbc91SGabor Kovesdan.It Fl M, Fl Fl month-sort, Fl Fl sort=month
185c66bbc91SGabor KovesdanSort by month abbreviations.
186c66bbc91SGabor KovesdanUnknown strings are considered smaller than the month names.
187c66bbc91SGabor Kovesdan.It Fl n , Fl Fl numeric-sort, Fl Fl sort=numeric
188c66bbc91SGabor KovesdanSort fields numerically by arithmetic value.
189c66bbc91SGabor KovesdanFields are supposed to have optional blanks in the beginning, an
190c66bbc91SGabor Kovesdanoptional minus sign, zero or more digits (including decimal point and
191c66bbc91SGabor Kovesdanpossible thousand separators).
192c66bbc91SGabor Kovesdan.It Fl R, Fl Fl random-sort, Fl Fl sort=random
193c66bbc91SGabor KovesdanSort by a random order.
194c66bbc91SGabor KovesdanThis is a random permutation of the inputs except that
195c66bbc91SGabor Kovesdanthe equal keys sort together.
196c66bbc91SGabor KovesdanIt is implemented by hashing the input keys and sorting
197c66bbc91SGabor Kovesdanthe hash values.
198b1a40986SPedro F. GiffuniThe hash function is chosen randomly.
199c66bbc91SGabor KovesdanThe hash function is randomized by
200c66bbc91SGabor Kovesdan.Cm /dev/random
201c66bbc91SGabor Kovesdancontent, or by file content if it is specified by
202c66bbc91SGabor Kovesdan.Fl Fl random-source .
203c66bbc91SGabor KovesdanEven if multiple sort fields are specified,
204c66bbc91SGabor Kovesdanthe same random hash function is used for all of them.
205c66bbc91SGabor Kovesdan.It Fl r , Fl Fl reverse
206c66bbc91SGabor KovesdanSort in reverse order.
207c66bbc91SGabor Kovesdan.It Fl V, Fl Fl version-sort
208c66bbc91SGabor KovesdanSort version numbers.
209c66bbc91SGabor KovesdanThe input lines are treated as file names in form
210c66bbc91SGabor KovesdanPREFIX VERSION SUFFIX, where SUFFIX matches the regular expression
211c66bbc91SGabor Kovesdan"(\.([A-Za-z~][A-Za-z0-9~]*)?)*".
212c66bbc91SGabor KovesdanThe files are compared by their prefixes and versions (leading
213c66bbc91SGabor Kovesdanzeros are ignored in version numbers, see example below).
214c66bbc91SGabor KovesdanIf an input string does not match the pattern, then it is compared
215c66bbc91SGabor Kovesdanusing the byte compare function.
216b1a40986SPedro F. GiffuniAll string comparisons are performed in C locale, the locale
217c66bbc91SGabor Kovesdanenvironment setting is ignored.
218c66bbc91SGabor Kovesdan.Bl -tag -width indent
219c66bbc91SGabor Kovesdan.It Example:
220c66bbc91SGabor Kovesdan.It $ ls sort* | sort -V
221c66bbc91SGabor Kovesdan.It sort-1.022.tgz
222c66bbc91SGabor Kovesdan.It sort-1.23.tgz
223c66bbc91SGabor Kovesdan.It sort-1.23.1.tgz
224c66bbc91SGabor Kovesdan.It sort-1.024.tgz
225c66bbc91SGabor Kovesdan.It sort-1.024.003.
226c66bbc91SGabor Kovesdan.It sort-1.024.003.tgz
227c66bbc91SGabor Kovesdan.It sort-1.024.07.tgz
228c66bbc91SGabor Kovesdan.It sort-1.024.009.tgz
229c66bbc91SGabor Kovesdan.El
230c66bbc91SGabor Kovesdan.El
231c66bbc91SGabor Kovesdan.Pp
232c66bbc91SGabor KovesdanThe treatment of field separators can be altered using these options:
233c66bbc91SGabor Kovesdan.Bl -tag -width indent
234c66bbc91SGabor Kovesdan.It Fl b , Fl Fl ignore-leading-blanks
235c66bbc91SGabor KovesdanIgnore leading blank space when determining the start
236c66bbc91SGabor Kovesdanand end of a restricted sort key (see
237c66bbc91SGabor Kovesdan.Fl k
238c66bbc91SGabor Kovesdan).
239c66bbc91SGabor KovesdanIf
240c66bbc91SGabor Kovesdan.Fl b
241c66bbc91SGabor Kovesdanis specified before the first
242c66bbc91SGabor Kovesdan.Fl k
243c66bbc91SGabor Kovesdanoption, it applies globally to all key specifications.
244c66bbc91SGabor KovesdanOtherwise,
245c66bbc91SGabor Kovesdan.Fl b
246c66bbc91SGabor Kovesdancan be attached independently to each
247c66bbc91SGabor Kovesdan.Ar field
248c66bbc91SGabor Kovesdanargument of the key specifications.
249c66bbc91SGabor Kovesdan.Fl b .
250c66bbc91SGabor Kovesdan.It Xo
251*f79477ebSPedro F. Giffuni.Fl k Ar field1 Ns Op , Ns Ar field2 ,
252*f79477ebSPedro F. Giffuni.Fl Fl key Ns = Ns Ar field1 Ns Op , Ns Ar field2
253c66bbc91SGabor Kovesdan.Xc
254c66bbc91SGabor KovesdanDefine a restricted sort key that has the starting position
255c66bbc91SGabor Kovesdan.Ar field1 ,
256c66bbc91SGabor Kovesdanand optional ending position
257c66bbc91SGabor Kovesdan.Ar field2
258c66bbc91SGabor Kovesdanof a key field.
259c66bbc91SGabor KovesdanThe
260c66bbc91SGabor Kovesdan.Fl k
261c66bbc91SGabor Kovesdanoption may be specified multiple times,
262c66bbc91SGabor Kovesdanin which case subsequent keys are compared when earlier keys compare equal.
263c66bbc91SGabor KovesdanThe
264c66bbc91SGabor Kovesdan.Fl k
265c66bbc91SGabor Kovesdanoption replaces the obsolete options
266c66bbc91SGabor Kovesdan.Cm \(pl Ns Ar pos1
267c66bbc91SGabor Kovesdanand
268c66bbc91SGabor Kovesdan.Fl Ns Ar pos2 ,
269c66bbc91SGabor Kovesdanbut the old notation is also supported.
270c66bbc91SGabor Kovesdan.It Fl t Ar char , Fl Fl field-separator Ns = Ns Ar char
271c66bbc91SGabor KovesdanUse
272c66bbc91SGabor Kovesdan.Ar char
273c66bbc91SGabor Kovesdanas a field separator character.
274c66bbc91SGabor KovesdanThe initial
275c66bbc91SGabor Kovesdan.Ar char
276c66bbc91SGabor Kovesdanis not considered to be part of a field when determining key offsets.
277c66bbc91SGabor KovesdanEach occurrence of
278c66bbc91SGabor Kovesdan.Ar char
279c66bbc91SGabor Kovesdanis significant (for example,
280c66bbc91SGabor Kovesdan.Dq Ar charchar
281c66bbc91SGabor Kovesdandelimits an empty field).
282c66bbc91SGabor KovesdanIf
283c66bbc91SGabor Kovesdan.Fl t
284c66bbc91SGabor Kovesdanis not specified, the default field separator is a sequence of
285c66bbc91SGabor Kovesdanblank space characters, and consecutive blank spaces do
286c66bbc91SGabor Kovesdan.Em not
287c66bbc91SGabor Kovesdandelimit an empty field, however, the initial blank space
288c66bbc91SGabor Kovesdan.Em is
289c66bbc91SGabor Kovesdanconsidered part of a field when determining key offsets.
290c66bbc91SGabor KovesdanTo use NUL as field separator, use
291c66bbc91SGabor Kovesdan.Fl t
292c66bbc91SGabor Kovesdan\'\\0\'.
293c66bbc91SGabor Kovesdan.It Fl z , Fl Fl zero-terminated
294c66bbc91SGabor KovesdanUse NUL as record separator.
295c66bbc91SGabor KovesdanBy default, records in the files are supposed to be separated by
296c66bbc91SGabor Kovesdanthe newline characters.
297c66bbc91SGabor KovesdanWith this option, NUL (\'\\0\') is used as a record separator character.
298c66bbc91SGabor Kovesdan.El
299c66bbc91SGabor Kovesdan.Pp
300c66bbc91SGabor KovesdanOther options:
301c66bbc91SGabor Kovesdan.Bl -tag -width indent
302c66bbc91SGabor Kovesdan.It Fl Fl batch-size Ns = Ns Ar num
303c66bbc91SGabor KovesdanSpecify maximum number of files that can be opened by
304c66bbc91SGabor Kovesdan.Nm
305c66bbc91SGabor Kovesdanat once.
306c66bbc91SGabor KovesdanThis option affects behavior when having many input files or using
307c66bbc91SGabor Kovesdantemporary files.
308c66bbc91SGabor KovesdanThe default value is 16.
309c66bbc91SGabor Kovesdan.It Fl Fl compress-program Ns = Ns Ar PROGRAM
310c66bbc91SGabor KovesdanUse PROGRAM to compress temporary files.
311c66bbc91SGabor KovesdanPROGRAM must compress standard input to standard output, when called
312c66bbc91SGabor Kovesdanwithout arguments.
313c66bbc91SGabor KovesdanWhen called with argument
314c66bbc91SGabor Kovesdan.Fl d
315c66bbc91SGabor Kovesdanit must decompress standard input to standard output.
316c66bbc91SGabor KovesdanIf PROGRAM fails,
317c66bbc91SGabor Kovesdan.Nm
318c66bbc91SGabor Kovesdanmust exit with error.
319c66bbc91SGabor KovesdanAn example of PROGRAM that can be used here is bzip2.
320c66bbc91SGabor Kovesdan.It Fl Fl random-source Ns = Ns Ar filename
321c66bbc91SGabor KovesdanIn random sort, the file content is used as the source of the 'seed' data
322c66bbc91SGabor Kovesdanfor the hash function choice.
323c66bbc91SGabor KovesdanTwo invocations of random sort with the same seed data will use
324c66bbc91SGabor Kovesdanthe same hash function and will produce the same result if the input is
325c66bbc91SGabor Kovesdanalso identical.
326c66bbc91SGabor KovesdanBy default, file
327c66bbc91SGabor Kovesdan.Cm /dev/random
328c66bbc91SGabor Kovesdanis used.
329c66bbc91SGabor Kovesdan.It Fl Fl debug
330c66bbc91SGabor KovesdanPrint some extra information about the sorting process to the
331c66bbc91SGabor Kovesdanstandard output.
3325d5151aeSGabor Kovesdan%%THREADS%%.It Fl Fl parallel
333c66bbc91SGabor Kovesdan%%THREADS%%Set the maximum number of execution threads.
334c66bbc91SGabor Kovesdan%%THREADS%%Default number equals to the number of CPUs.
335c66bbc91SGabor Kovesdan.It Fl Fl files0-from Ns = Ns Ar filename
336c66bbc91SGabor KovesdanTake the input file list from the file
337c66bbc91SGabor Kovesdan.Ar filename .
338c66bbc91SGabor KovesdanThe file names must be separated by NUL
339c66bbc91SGabor Kovesdan(like the output produced by the command "find ... -print0").
340c66bbc91SGabor Kovesdan.It Fl Fl radixsort
341c66bbc91SGabor KovesdanTry to use radix sort, if the sort specifications allow.
342c66bbc91SGabor KovesdanThe radix sort can only be used for trivial locales (C and POSIX),
343c66bbc91SGabor Kovesdanand it cannot be used for numeric or month sort.
344c66bbc91SGabor KovesdanRadix sort is very fast and stable.
345c66bbc91SGabor Kovesdan.It Fl Fl mergesort
346c66bbc91SGabor KovesdanUse mergesort.
347c66bbc91SGabor KovesdanThis is a universal algorithm that can always be used,
348c66bbc91SGabor Kovesdanbut it is not always the fastest.
349c66bbc91SGabor Kovesdan.It Fl Fl qsort
350c66bbc91SGabor KovesdanTry to use quick sort, if the sort specifications allow.
351c66bbc91SGabor KovesdanThis sort algorithm cannot be used with
352c66bbc91SGabor Kovesdan.Fl u
353c66bbc91SGabor Kovesdanand
354c66bbc91SGabor Kovesdan.Fl s .
355c66bbc91SGabor Kovesdan.It Fl Fl heapsort
356c66bbc91SGabor KovesdanTry to use heap sort, if the sort specifications allow.
357c66bbc91SGabor KovesdanThis sort algorithm cannot be used with
358c66bbc91SGabor Kovesdan.Fl u
359c66bbc91SGabor Kovesdanand
360c66bbc91SGabor Kovesdan.Fl s .
3615ca724dcSGabor Kovesdan.It Fl Fl mmap
3625ca724dcSGabor KovesdanTry to use file memory mapping system call.
3635ca724dcSGabor KovesdanIt may increase speed in some cases.
364c66bbc91SGabor Kovesdan.El
365c66bbc91SGabor Kovesdan.Pp
366c66bbc91SGabor KovesdanThe following operands are available:
367c66bbc91SGabor Kovesdan.Bl -tag -width indent
368c66bbc91SGabor Kovesdan.It Ar file
369c66bbc91SGabor KovesdanThe pathname of a file to be sorted, merged, or checked.
370c66bbc91SGabor KovesdanIf no
371c66bbc91SGabor Kovesdan.Ar file
372c66bbc91SGabor Kovesdanoperands are specified, or if a
373c66bbc91SGabor Kovesdan.Ar file
374c66bbc91SGabor Kovesdanoperand is
375c66bbc91SGabor Kovesdan.Fl ,
376c66bbc91SGabor Kovesdanthe standard input is used.
377c66bbc91SGabor Kovesdan.El
378c66bbc91SGabor Kovesdan.Pp
379c66bbc91SGabor KovesdanA field is defined as a maximal sequence of characters other than the
380c66bbc91SGabor Kovesdanfield separator and record separator (newline by default).
381c66bbc91SGabor KovesdanInitial blank spaces are included in the field unless
382c66bbc91SGabor Kovesdan.Fl b
383c66bbc91SGabor Kovesdanhas been specified;
384c66bbc91SGabor Kovesdanthe first blank space of a sequence of blank spaces acts as the field
385c66bbc91SGabor Kovesdanseparator and is included in the field (unless
386c66bbc91SGabor Kovesdan.Fl t
387c66bbc91SGabor Kovesdanis specified).
388c66bbc91SGabor KovesdanFor example, all blank spaces at the beginning of a line are
389c66bbc91SGabor Kovesdanconsidered to be part of the first field.
390c66bbc91SGabor Kovesdan.Pp
391c66bbc91SGabor KovesdanFields are specified by the
392c66bbc91SGabor Kovesdan.Sm off
393c66bbc91SGabor Kovesdan.Fl k\ \& Ar field1 Op , Ar field2
394c66bbc91SGabor Kovesdan.Sm on
395c66bbc91SGabor Kovesdancommand-line option.
396c66bbc91SGabor KovesdanIf
397c66bbc91SGabor Kovesdan.Ar field2
398c66bbc91SGabor Kovesdanis missing, the end of the key defaults to the end of the line.
399c66bbc91SGabor Kovesdan.Pp
400c66bbc91SGabor KovesdanThe arguments
401c66bbc91SGabor Kovesdan.Ar field1
402c66bbc91SGabor Kovesdanand
403c66bbc91SGabor Kovesdan.Ar field2
404c66bbc91SGabor Kovesdanhave the form
405c66bbc91SGabor Kovesdan.Em m.n
406c66bbc91SGabor Kovesdan.Em (m,n > 0)
407c66bbc91SGabor Kovesdanand can be followed by one or more of the modifiers
408c66bbc91SGabor Kovesdan.Cm b , d , f , i ,
409c66bbc91SGabor Kovesdan.Cm n , g , M
410c66bbc91SGabor Kovesdanand
411c66bbc91SGabor Kovesdan.Cm r ,
412c66bbc91SGabor Kovesdanwhich correspond to the options discussed above.
413c66bbc91SGabor KovesdanWhen
414c66bbc91SGabor Kovesdan.Cm b
415c66bbc91SGabor Kovesdanis specified it applies only to
416c66bbc91SGabor Kovesdan.Ar field1
417c66bbc91SGabor Kovesdanor
418c66bbc91SGabor Kovesdan.Ar field2
419c66bbc91SGabor Kovesdanwhere it is specified while the rest of the modifiers
420c66bbc91SGabor Kovesdanapply to the whole key field regardless if they are
421c66bbc91SGabor Kovesdanspecified only with
422c66bbc91SGabor Kovesdan.Ar field1
423c66bbc91SGabor Kovesdanor
424c66bbc91SGabor Kovesdan.Ar field2
425c66bbc91SGabor Kovesdanor both.
426c66bbc91SGabor KovesdanA
427c66bbc91SGabor Kovesdan.Ar field1
428c66bbc91SGabor Kovesdanposition specified by
429c66bbc91SGabor Kovesdan.Em m.n
430c66bbc91SGabor Kovesdanis interpreted as the
431c66bbc91SGabor Kovesdan.Em n Ns th
432c66bbc91SGabor Kovesdancharacter from the beginning of the
433c66bbc91SGabor Kovesdan.Em m Ns th
434c66bbc91SGabor Kovesdanfield.
435c66bbc91SGabor KovesdanA missing
436c66bbc91SGabor Kovesdan.Em \&.n
437c66bbc91SGabor Kovesdanin
438c66bbc91SGabor Kovesdan.Ar field1
439c66bbc91SGabor Kovesdanmeans
440c66bbc91SGabor Kovesdan.Ql \&.1 ,
441c66bbc91SGabor Kovesdanindicating the first character of the
442c66bbc91SGabor Kovesdan.Em m Ns th
443c66bbc91SGabor Kovesdanfield; if the
444c66bbc91SGabor Kovesdan.Fl b
445c66bbc91SGabor Kovesdanoption is in effect,
446c66bbc91SGabor Kovesdan.Em n
447c66bbc91SGabor Kovesdanis counted from the first non-blank character in the
448c66bbc91SGabor Kovesdan.Em m Ns th
449c66bbc91SGabor Kovesdanfield;
450c66bbc91SGabor Kovesdan.Em m Ns \&.1b
451c66bbc91SGabor Kovesdanrefers to the first non-blank character in the
452c66bbc91SGabor Kovesdan.Em m Ns th
453c66bbc91SGabor Kovesdanfield.
454c66bbc91SGabor Kovesdan.No 1\&. Ns Em n
455c66bbc91SGabor Kovesdanrefers to the
456c66bbc91SGabor Kovesdan.Em n Ns th
457c66bbc91SGabor Kovesdancharacter from the beginning of the line;
458c66bbc91SGabor Kovesdanif
459c66bbc91SGabor Kovesdan.Em n
460c66bbc91SGabor Kovesdanis greater than the length of the line, the field is taken to be empty.
461c66bbc91SGabor Kovesdan.Pp
462c66bbc91SGabor Kovesdan.Em n Ns th
463c66bbc91SGabor Kovesdanpositions are always counted from the field beginning, even if the field
464c66bbc91SGabor Kovesdanis shorter than the number of specified positions.
465c66bbc91SGabor KovesdanThus, the key can really start from a position in a subsequent field.
466c66bbc91SGabor Kovesdan.Pp
467c66bbc91SGabor KovesdanA
468c66bbc91SGabor Kovesdan.Ar field2
469c66bbc91SGabor Kovesdanposition specified by
470c66bbc91SGabor Kovesdan.Em m.n
471c66bbc91SGabor Kovesdanis interpreted as the
472c66bbc91SGabor Kovesdan.Em n Ns th
473c66bbc91SGabor Kovesdancharacter (including separators) from the beginning of the
474c66bbc91SGabor Kovesdan.Em m Ns th
475c66bbc91SGabor Kovesdanfield.
476c66bbc91SGabor KovesdanA missing
477c66bbc91SGabor Kovesdan.Em \&.n
478c66bbc91SGabor Kovesdanindicates the last character of the
479c66bbc91SGabor Kovesdan.Em m Ns th
480c66bbc91SGabor Kovesdanfield;
481c66bbc91SGabor Kovesdan.Em m
482c66bbc91SGabor Kovesdan= \&0
483c66bbc91SGabor Kovesdandesignates the end of a line.
484c66bbc91SGabor KovesdanThus the option
485c66bbc91SGabor Kovesdan.Fl k Ar v.x,w.y
486c66bbc91SGabor Kovesdanis synonymous with the obsolete option
487c66bbc91SGabor Kovesdan.Cm \(pl Ns Ar v-\&1.x-\&1
488c66bbc91SGabor Kovesdan.Fl Ns Ar w-\&1.y ;
489c66bbc91SGabor Kovesdanwhen
490c66bbc91SGabor Kovesdan.Em y
491c66bbc91SGabor Kovesdanis omitted,
492c66bbc91SGabor Kovesdan.Fl k Ar v.x,w
493c66bbc91SGabor Kovesdanis synonymous with
494c66bbc91SGabor Kovesdan.Cm \(pl Ns Ar v-\&1.x-\&1
495c66bbc91SGabor Kovesdan.Fl Ns Ar w\&.0 .
496c66bbc91SGabor KovesdanThe obsolete
497c66bbc91SGabor Kovesdan.Cm \(pl Ns Ar pos1
498c66bbc91SGabor Kovesdan.Fl Ns Ar pos2
499c66bbc91SGabor Kovesdanoption is still supported, except for
500c66bbc91SGabor Kovesdan.Fl Ns Ar w\&.0b ,
501c66bbc91SGabor Kovesdanwhich has no
502c66bbc91SGabor Kovesdan.Fl k
503c66bbc91SGabor Kovesdanequivalent.
504c66bbc91SGabor Kovesdan.Sh ENVIRONMENT
505c66bbc91SGabor Kovesdan.Bl -tag -width Fl
506c66bbc91SGabor Kovesdan.It Ev LC_COLLATE
507c66bbc91SGabor KovesdanLocale settings to be used to determine the collation for
508c66bbc91SGabor Kovesdansorting records.
509c66bbc91SGabor Kovesdan.It Ev LC_CTYPE
510c66bbc91SGabor KovesdanLocale settings to be used to case conversion and classification
511c66bbc91SGabor Kovesdanof characters, that is, which characters are considered
512c66bbc91SGabor Kovesdanwhitespaces, etc.
513c66bbc91SGabor Kovesdan.It Ev LC_MESSAGES
514c66bbc91SGabor KovesdanLocale settings that determine the language of output messages
515c66bbc91SGabor Kovesdanthat
516c66bbc91SGabor Kovesdan.Nm
517c66bbc91SGabor Kovesdanprints out.
518c66bbc91SGabor Kovesdan.It Ev LC_NUMERIC
519c66bbc91SGabor KovesdanLocale settings that determine the number format used in numeric sort.
520c66bbc91SGabor Kovesdan.It Ev LC_TIME
521c66bbc91SGabor KovesdanLocale settings that determine the month format used in month sort.
522c66bbc91SGabor Kovesdan.It Ev LC_ALL
523c66bbc91SGabor KovesdanLocale settings that override all of the above locale settings.
524c66bbc91SGabor KovesdanThis environment variable can be used to set all these settings
525c66bbc91SGabor Kovesdanto the same value at once.
526c66bbc91SGabor Kovesdan.It Ev LANG
527c66bbc91SGabor KovesdanUsed as a last resort to determine different kinds of locale-specific
528c66bbc91SGabor Kovesdanbehavior if neither the respective environment variable, nor
529c66bbc91SGabor Kovesdan.Ev LC_ALL
530c66bbc91SGabor Kovesdanare set.
531c66bbc91SGabor Kovesdan%%NLS%%.It Ev NLSPATH
532c66bbc91SGabor Kovesdan%%NLS%%Path to NLS catalogs.
533c66bbc91SGabor Kovesdan.It Ev TMPDIR
534c66bbc91SGabor KovesdanPath to the directory in which temporary files will be stored.
535c66bbc91SGabor KovesdanNote that
536c66bbc91SGabor Kovesdan.Ev TMPDIR
537c66bbc91SGabor Kovesdanmay be overridden by the
538c66bbc91SGabor Kovesdan.Fl T
539c66bbc91SGabor Kovesdanoption.
540c66bbc91SGabor Kovesdan.It Ev GNUSORT_NUMERIC_COMPATIBILITY
541c66bbc91SGabor KovesdanIf defined
542c66bbc91SGabor Kovesdan.Fl t
543c66bbc91SGabor Kovesdanwill not override the locale numeric symbols, that is, thousand
544c66bbc91SGabor Kovesdanseparators and decimal separators.
545c66bbc91SGabor KovesdanBy default, if we specify
546c66bbc91SGabor Kovesdan.Fl t
547c66bbc91SGabor Kovesdanwith the same symbol as the thousand separator or decimal point,
548c66bbc91SGabor Kovesdanthe symbol will be treated as the field separator.
549c66bbc91SGabor KovesdanOlder behavior was less definite; the symbol was treated as both field
550c66bbc91SGabor Kovesdanseparator and numeric separator, simultaneously.
551c66bbc91SGabor KovesdanThis environment variable enables the old behavior.
552c66bbc91SGabor Kovesdan.El
553c66bbc91SGabor Kovesdan.Sh FILES
554c66bbc91SGabor Kovesdan.Bl -tag -width Pa -compact
555c66bbc91SGabor Kovesdan.It Pa /var/tmp/.bsdsort.PID.*
556c66bbc91SGabor KovesdanTemporary files.
557c66bbc91SGabor Kovesdan.It Pa /dev/random
558c66bbc91SGabor KovesdanDefault seed file for the random sort.
559c66bbc91SGabor Kovesdan.El
5602dbc3019SJoel Dahl.Sh EXIT STATUS
5612dbc3019SJoel DahlThe
5622dbc3019SJoel Dahl.Nm
5632dbc3019SJoel Dahlutility shall exit with one of the following values:
5642dbc3019SJoel Dahl.Pp
5652dbc3019SJoel Dahl.Bl -tag -width flag -compact
5662dbc3019SJoel Dahl.It 0
5672dbc3019SJoel DahlSuccessfully sorted the input files or if used with
5682dbc3019SJoel Dahl.Fl c
5692dbc3019SJoel Dahlor
5702dbc3019SJoel Dahl.Fl C ,
5712dbc3019SJoel Dahlthe input file already met the sorting criteria.
5722dbc3019SJoel Dahl.It 1
5732dbc3019SJoel DahlOn disorder (or non-uniqueness) with the
5742dbc3019SJoel Dahl.Fl c
5752dbc3019SJoel Dahlor
5762dbc3019SJoel Dahl.Fl C
5772dbc3019SJoel Dahloptions.
5782dbc3019SJoel Dahl.It 2
5792dbc3019SJoel DahlAn error occurred.
5802dbc3019SJoel Dahl.El
581c66bbc91SGabor Kovesdan.Sh SEE ALSO
582c66bbc91SGabor Kovesdan.Xr comm 1 ,
583c66bbc91SGabor Kovesdan.Xr join 1 ,
58496c566eaSGlen Barber.Xr uniq 1
585c66bbc91SGabor Kovesdan.Sh STANDARDS
586c66bbc91SGabor KovesdanThe
587c66bbc91SGabor Kovesdan.Nm
588c66bbc91SGabor Kovesdanutility is compliant with the
589c66bbc91SGabor Kovesdan.St -p1003.1-2008
590c66bbc91SGabor Kovesdanspecification.
591c66bbc91SGabor Kovesdan.Pp
592c66bbc91SGabor KovesdanThe flags
593c66bbc91SGabor Kovesdan.Op Fl ghRMSsTVz
594c66bbc91SGabor Kovesdanare extensions to the POSIX specification.
595c66bbc91SGabor Kovesdan.Pp
596c66bbc91SGabor KovesdanAll long options are extensions to the specification, some of them are
597c66bbc91SGabor Kovesdanprovided for compatibility with GNU versions and some of them are
598c66bbc91SGabor Kovesdanown extensions.
599c66bbc91SGabor Kovesdan.Pp
600c66bbc91SGabor KovesdanThe old key notations
601c66bbc91SGabor Kovesdan.Cm \(pl Ns Ar pos1
602c66bbc91SGabor Kovesdanand
603c66bbc91SGabor Kovesdan.Fl Ns Ar pos2
604c66bbc91SGabor Kovesdancome from older versions of
605c66bbc91SGabor Kovesdan.Nm
606c66bbc91SGabor Kovesdanand are still supported but their use is highly discouraged.
607c66bbc91SGabor Kovesdan.Sh HISTORY
608c66bbc91SGabor KovesdanA
609c66bbc91SGabor Kovesdan.Nm
610c66bbc91SGabor Kovesdancommand first appeared in
611c66bbc91SGabor Kovesdan.At v3 .
612c66bbc91SGabor Kovesdan.Sh AUTHORS
613385385fbSJoel Dahl.An Gabor Kovesdan Aq Mt gabor@FreeBSD.org ,
614c66bbc91SGabor Kovesdan.Pp
615385385fbSJoel Dahl.An Oleg Moskalenko Aq Mt mom040267@gmail.com
616c66bbc91SGabor Kovesdan.Sh NOTES
617c66bbc91SGabor KovesdanThis implementation of
618c66bbc91SGabor Kovesdan.Nm
619c66bbc91SGabor Kovesdanhas no limits on input line length (other than imposed by available
620c66bbc91SGabor Kovesdanmemory) or any restrictions on bytes allowed within lines.
621c66bbc91SGabor Kovesdan.Pp
622c66bbc91SGabor KovesdanThe performance depends highly on locale settings,
623c66bbc91SGabor Kovesdanefficient choice of sort keys and key complexity.
624c66bbc91SGabor KovesdanThe fastest sort is with locale C, on whole lines,
625c66bbc91SGabor Kovesdanwith option
626c66bbc91SGabor Kovesdan.Fl s.
627c66bbc91SGabor KovesdanIn general, locale C is the fastest, then single-byte
628c66bbc91SGabor Kovesdanlocales follow and multi-byte locales as the slowest but
629c66bbc91SGabor Kovesdanthe correct collation order is always respected.
630c66bbc91SGabor KovesdanAs for the key specification, the simpler to process the
631c66bbc91SGabor Kovesdanlines the faster the search will be.
632c66bbc91SGabor Kovesdan.Pp
633c66bbc91SGabor KovesdanWhen sorting by arithmetic value, using
634c66bbc91SGabor Kovesdan.Fl n
635c66bbc91SGabor Kovesdanresults in much better performance than
636c66bbc91SGabor Kovesdan.Fl g
637c66bbc91SGabor Kovesdanso its use is encouraged
638c66bbc91SGabor Kovesdanwhenever possible.
639