1.\" Copyright (c) 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.roff% 5.\" 6.\" @(#)sort.1 6.7 (Berkeley) 04/26/91 7.\" 8.Dd 9.Dt SORT 1 10.Os 11.Sh NAME 12.Nm sort 13.Nd sort or merge text files 14.Sh SYNOPSIS 15.Nm sort 16.Op Fl mubdfinrtx 17.Oo 18.Cm \(pl Ns Ar pos1 19.Op Fl Ns Ar pos2 20.Oc 21.Ar ... 22.Op Fl o Ar output 23.Op Fl T Ar directory 24.Op Ar file 25.Ar ... 26.Sh DESCRIPTION 27The 28.Nm sort 29utility 30sorts text files by lines. 31Comparisons are based on one or more sort keys (or fields) extracted 32from each line of input, and are performed 33lexicographically. By default, if keys are not given, 34.Nm sort 35regards each input line as a single field. 36.Pp 37The following options are available: 38.Bl -tag -width indent 39.It Fl c 40Check that the single input file is sorted lexicographically. 41If the file is not sorted, 42.Nm sort 43sorts it and writes the sorted output to the standard output or the 44filename specified by the 45.Fl o 46option. 47.It Fl m 48Merge only; the input files are assumed to be pre-sorted. 49.It Fl o Ar output 50The argument given is the name of an 51.Ar output 52file to 53be used instead of the standard output. 54This file 55can be the same as one of the input files. 56.It Fl T Ar directory 57The argument 58.Ar directory 59is used for creating temporary files. 60.It Fl u 61Unique: suppress all but one in each set of lines 62having equal keys. 63If used with the 64.Fl c 65option, 66check that there are no lines with duplicate keys. 67.El 68.Pp 69The following options override the default ordering rules. 70When ordering options appear independent of key field 71specifications, the requested field ordering rules are 72applied globally to all sort keys. 73.\" When attached to a 74.\" specific key 75.\" (see 76.\" .Fl k ) , 77.\" the specified ordering options override 78.\" all global ordering options for that key. 79.Bl -tag -width indent 80.It Fl d 81Only blank space and alphanumeric characters 82.\" according 83.\" to the current setting of LC_CTYPE 84are used 85in making comparisons. 86.It Fl f 87Considers all lowercase characters that have uppercase 88equivalents to be the same for purposes of 89comparison. 90.It Fl i 91Ignore all non-printable characters. 92.It Fl n 93An initial numeric string, consisting of optional 94blank space, optional minus sign, and zero or more 95digits (including decimal point) 96.\" with 97.\" optional radix character and thousands 98.\" separator 99.\" (as defined in the current locale), 100is sorted by arithmetic value. 101The 102.Fl n 103option implies 104the 105.Fl b 106option. (See below.) 107Note that the 108.Fl b 109option 110is only effective when key fields have been specified 111and that 112.Fl \&0 113is considered equal to zero. 114.optional It Fl r 115Reverse the sense of comparisons. 116.El 117.Pp 118The treatment of field separators can be altered using the 119options: 120.Bl -tag -width indent 121.It Fl b 122Leading blank spaces are ignored when determining the starting 123ending positions of a restricted sort key. 124If the 125.Fl b 126option is specified before the first 127.Cm \(pl Ns Ar pos1 128argument, it shall be applied to all 129.Cm \(pl Ns Ar pos1 130arguments. 131Otherwise, the 132.Fl b 133option can be 134attached independently to each 135.Cm \(pl Ns Ar pos1 136or 137.Fl Ar pos2 138argument (see below). 139.It Fl t Ar char 140.Ar Char 141is used as the field separator character; 142.Ar char 143is not considered to be part of a field (although it 144can be included in a sort key). 145Each occurrence of 146.Ar char 147is significant (for example, 148.Dq Ar charchar 149delimits an empty field). 150If 151.Fl t 152is not specified, 153blank space characters are used as default field 154separators. 155.It Cm \(pl Ns Ar pos1 156Designates the start position of a key field. 157.It Fl Ns Ar pos1 158Designates the end position of a key field. 159.El 160.Pp 161The following operands are available: 162.Bl -tag -width indent 163.Ar file 164The pathname of a file to be sorted, merged, or checked. 165If no file 166operands are specified, or if 167a file operand is 168.Fl , 169the standard input is used. 170.Pp 171A field is 172defined as a minimal sequence of characters followed by a 173field separator or a newline character. 174By default, the first 175blank space of a sequence of blank spaces acts as the field separator. 176All blank spaces in a sequence of blank spaces are considered 177to be part of the next field; for example, all blank spaces at 178the beginning of a line are considered to be part of the 179first field. 180.Pp 181Fields are specified 182by the 183.Cm \(pl Ns Ar pos1 184and 185.Fl Ar pos2 186arguments. A missing 187.Cm \(pl Ns Ar pos1 188argument defaults to the beginning of a line. 189A missing 190.Fl Ar pos2 191argument defaults to the end of a line. 192.Pp 193The arguments 194.Cm \(pl Ns Ar pos1 195and 196.Fl Ar pos2 197have the form 198.Em m.n 199followed by one or more of the options 200.Fl b , d , f , i , 201.Fl n , r . 202A 203.Cm \(pl Ns Ar pos1 204position specified by 205.Em m.n 206is interpreted to 207mean the 208.Em n Ns th 209character in the 210.Em m Ns \(pl1th 211field. 212A missing 213.Em \&.n 214means 215.Ql \&.0 , 216indicating the first character of the 217.Em m Ns \(pl1th 218field. 219If the 220.Fl b 221option is in effect, 222.Em n 223is counted from the first 224non-blank character in the 225.Em m Ns \(pl1th 226field; 227.Em m Ns \&.0b 228refers to the first 229non-blank character in the 230.Em m Ns \(pl1th 231field. 232.Pp 233A 234.Fl Ar pos2 235position specified by 236.Em m.n 237is interpreted to mean 238the 239.Em n Ns th 240character (including separators) after the last 241character of the 242.Em m Ns th 243field. 244A missing 245.Em \&.n 246means 247.Ql \&.0 , 248indicating 249the last character of the 250.Em m Ns th 251field. 252If the 253.Fl b 254option 255is in effect, 256.Em n 257is counted from the last leading blank character in 258the 259.Em m Ns \(pl1th 260field; 261.Em m Ns \&.1b 262refers to the first non-blank character in the 263.Em m Ns \(pl1th 264field. 265.Sh FILES 266.Bl -tag -width Pa -compact 267.It Pa /var/tmp/stm*, /tmp/* 268Default temporary directories (in order of search). 269.El 270.Sh SEE ALSO 271.Xr comm 1 , 272.Xr uniq 1 , 273.Xr join 1 274.Sh DIAGNOSTICS 275.Sh BUGS 276Lines which are longer than 4096 are discarded and processing continues. 277.Sh HISTORY 278A 279.Nm 280command appeared in 281.At v6 . 282