aboutsummaryrefslogtreecommitdiff
path: root/man/man1/sort.html
blob: 2f6de1b72273540be5b2f06dbef92c4b2564a5e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<head>
<title>sort(1) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>SORT(1)</b><td align=right><b>SORT(1)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    sort &ndash; sort and/or merge files<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>sort</font></tt> [ <tt><font size=+1>&#8722;cmuMbdfinrwt</font></tt><i>x</i> ] [ <tt><font size=+1>+</font></tt><i>pos1</i> [ <tt><font size=+1>&#8722;</font></tt><i>pos2</i> ] ... ] ... [ <tt><font size=+1>&#8722;k</font></tt> <i>pos1</i>
    [ <i>,pos2</i> ] ] ...<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            &#8217; [ <tt><font size=+1>&#8722;o</font></tt> <i>output</i> ] [ <tt><font size=+1>&#8722;T</font></tt> <i>dir</i> ... ] [ <i>option</i> ... ] [ <i>file</i> ... ]<br>
            
        </table>
        
    </table>
    
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Sort</i> sorts lines of all the <i>files</i> together and writes the result
    on the standard output. If no input files are named, the standard
    input is sorted. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The default sort key is an entire line. Default ordering is lexicographic
    by runes. The ordering is affected globally by the following options,
    one or more of which may appear.<br>
    <tt><font size=+1>&#8722;M</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Compare as months. The first three non-white space characters
    of the field are folded to upper case and compared so that <tt><font size=+1>JAN</font></tt>
    precedes <tt><font size=+1>FEB</font></tt>, etc. Invalid fields compare low to <tt><font size=+1>JAN</font></tt>.<br>
    <tt><font size=+1>&#8722;b</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Ignore leading white space (spaces and tabs) in field comparisons.<br>
    <tt><font size=+1>&#8722;d</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&#8216;Phone directory&#8217; order: only letters, accented letters, digits
    and white space are significant in comparisons.<br>
    <tt><font size=+1>&#8722;f</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Fold lower case letters onto upper case. Accented characters
    are folded to their non-accented upper case form.<br>
    <tt><font size=+1>&#8722;i</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Ignore characters outside the ASCII range 040-0176 in non-numeric
    comparisons.<br>
    <tt><font size=+1>&#8722;w</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Like <tt><font size=+1>&#8722;i</font></tt>, but ignore only tabs and spaces.<br>
    <tt><font size=+1>&#8722;n</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;An initial numeric string, consisting of optional white space,
    optional plus or minus sign, and zero or more digits with optional
    decimal point, is sorted by arithmetic value.<br>
    <tt><font size=+1>&#8722;g</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Numbers, like <tt><font size=+1>&#8722;n</font></tt> but with optional <tt><font size=+1>e</font></tt>-style exponents, are sorted
    by value.<br>
    <tt><font size=+1>&#8722;r</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Reverse the sense of comparisons.<br>
    <tt><font size=+1>&#8722;t</font></tt><i>x</i>&nbsp;&nbsp;&nbsp;&#8216;Tab character&#8217; separating fields is <i>x</i>. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The notation <tt><font size=+1>+</font></tt><i>pos1</i> <tt><font size=+1>&#8722;</font></tt><i>pos2</i> restricts a sort key to a field beginning
    at <i>pos1</i> and ending just before <i>pos2</i>. <i>Pos1</i> and <i>pos2</i> each have the
    form <i>m</i><tt><font size=+1>.</font></tt><i>n</i>, optionally followed by one or more of the flags <tt><font size=+1>Mbdfginr</font></tt>,
    where <i>m</i> tells a number of fields to skip from the beginning of
    the line and <i>n</i> tells a number of characters to skip
    further. If any flags are present they override all the global
    ordering options for this key. A missing <tt><font size=+1>.</font></tt><i>n</i> means <tt><font size=+1>.0</font></tt>; a missing
    <tt><font size=+1>&#8722;</font></tt><i>pos2</i> means the end of the line. Under the <tt><font size=+1>&#8722;t</font></tt><i>x</i> option, fields
    are strings separated by <i>x</i>; otherwise fields are non-empty strings
    separated by white space. White space before a field is part of
    the field, except under option <tt><font size=+1>&#8722;b</font></tt>. A <tt><font size=+1>b</font></tt> flag may be attached independently
    to <i>pos1</i> and <i>pos2.</i> 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The notation <tt><font size=+1>&#8722;k</font></tt> <i>pos1</i>[,<i>pos2</i>] is how POSIX <i>sort</i> defines fields:
    <i>pos1</i> and <i>pos2</i> have the same format but different meanings. The
    value of <i>m</i> is origin 1 instead of origin 0 and a missing <tt><font size=+1>.</font></tt><i>n</i> in
    <i>pos2</i> is the end of the field. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    When there are multiple sort keys, later keys are compared only
    after all earlier keys compare equal. Lines that otherwise compare
    equal are ordered with all bytes significant. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    These option arguments are also understood:<br>
    <tt><font size=+1>&#8722;c</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Check that the single input file is sorted according to the
    ordering rules; give no output unless the file is out of sort.<br>
    <tt><font size=+1>&#8722;m</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Merge; assume the input files are already sorted.<br>
    <tt><font size=+1>&#8722;u</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Suppress all but one in each set of equal lines. Ignored bytes
    and bytes outside keys do not participate in this comparison.<br>
    <tt><font size=+1>&#8722;o</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The next argument is the name of an output file to use instead
    of the standard output. This file may be the same as one of the
    inputs.<br>
    <tt><font size=+1>&#8722;T</font></tt><i>dir</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Put temporary files in <i>dir</i> rather than in <tt><font size=+1>/var/tmp</font></tt>.<br>
    
</table>
<p><font size=+1><b>EXAMPLES     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>sort &#8722;u +0f +0 list<br>
    </font></tt>
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        Print in alphabetical order all the unique spellings in a list
        of words where capitalized words differ from uncapitalized.<br>
        
    </table>
    <tt><font size=+1>sort &#8722;t: +1 /adm/users<br>
    </font></tt>
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        Print the users file sorted by user name (the second colon-separated
        field).<br>
        
    </table>
    <tt><font size=+1>sort &#8722;umM dates<br>
    </font></tt>
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        Print the first instance of each month in an already sorted file.
        Options <tt><font size=+1>&#8722;um</font></tt> with just one input file make the choice of a unique
        representative from a set of equal lines predictable.<br>
        
    </table>
    <tt><font size=+1>grep &#8722;n '^' input | sort &#8722;t: +1f +0n | sed 's/[0&#8722;9]*://'<br>
    </font></tt>
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        A stable sort: input lines that compare equal will come out in
        their original order.<br>
        
    </table>
    
</table>
<p><font size=+1><b>FILES     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/var/tmp/sort.</font></tt><i>&lt;pid&gt;.&lt;ordinal&gt;<br>
    </i>
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/cmd/sort.c<br>
    </font></tt>
</table>
<p><font size=+1><b>SEE ALSO    </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <a href="../man1/uniq.html"><i>uniq</i>(1)</a>, <a href="../man1/look.html"><i>look</i>(1)</a><br>
    
</table>
<p><font size=+1><b>DIAGNOSTICS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Sort</i> comments and exits with non-null status for various trouble
    conditions and for disorder discovered under option <tt><font size=+1>&#8722;c</font></tt>.<br>
    
</table>
<p><font size=+1><b>BUGS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    An external null character can be confused with an internally
    generated end-of-field character. The result can make a sub-field
    not sort less than a longer field. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    Some of the options, e.g. <tt><font size=+1>&#8722;i</font></tt> and <tt><font size=+1>&#8722;M</font></tt>, are hopelessly provincial.<br>
    
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>