Skip to content

Commit 837a7d2

Browse files
committed
sort.1: Expand the examples section.
- Add an example using multiple sort keys. - Add sample data to a few examples.
1 parent cad73ba commit 837a7d2

1 file changed

Lines changed: 52 additions & 16 deletions

File tree

usr.bin/sort/sort.1

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" $NetBSD: sort.1,v 1.50 2026/01/18 21:49:53 jkoshy Exp $
1+
.\" $NetBSD: sort.1,v 1.51 2026/01/23 14:06:09 jkoshy Exp $
22
.\"
33
.\" Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
44
.\" All rights reserved.
@@ -59,7 +59,7 @@
5959
.\"
6060
.\" @(#)sort.1 8.1 (Berkeley) 6/6/93
6161
.\"
62-
.Dd January 18, 2026
62+
.Dd January 23, 2026
6363
.Dt SORT 1
6464
.Os
6565
.Sh NAME
@@ -524,23 +524,59 @@ use:
524524
.Pp
525525
.Dl $ sort -m file1 file2 file3
526526
.Pp
527-
To sort the lines in a file lexicographically using the second
528-
whitespace-separated field of each line as the sort key preserving any
529-
leading whitespace in the sort key, use:
527+
To sort lines lexicographically using the second whitespace-separated
528+
field of each line as the sort key preserving leading whitespace in
529+
the sort key, use:
530+
.Bd -literal -offset indent
531+
$ sort -k 2 <<EOF
532+
aa bb
533+
ab bb
534+
EOF
535+
ab bb
536+
aa bb
537+
$
538+
.Ed
530539
.Pp
531-
.Dl $ sort -k 2 file
540+
To sort lines lexicographically using the second whitespace-separated
541+
field on each line as the sort key ignoring any leading whitespace in
542+
the sort key, use:
543+
.Bd -literal -offset indent
544+
$ sort -k 2b <<EOF
545+
aa bb
546+
ab bb
547+
EOF
548+
aa bb
549+
ab bb
550+
$
551+
.Ed
532552
.Pp
533-
To sort the lines in a file lexicographically using the second
534-
whitespace-separated field on each line as the sort key ignoring any
535-
leading whitespace in the sort key, use:
553+
To sort lines numerically, using the second whitespace-separated field
554+
on each line as the sort key, starting the sort key at the second
555+
non-blank character within the field, use:
556+
.Bd -literal -offset indent
557+
$ sort -k 2.2nb <<EOF
558+
aa X42
559+
ab Y24
560+
EOF
561+
ab Y24
562+
aa X42
563+
$
564+
.Ed
536565
.Pp
537-
.Dl $ sort -k 2b file
538-
.Pp
539-
To sort the lines in a file numerically using the second
540-
whitespace-separated field on each line as the sort key, starting the
541-
sort key at the second non-blank character within the field, use:
542-
.Pp
543-
.Dl $ sort -k 2.2nb file
566+
To sort lines numerically with a sort key starting on the second
567+
character of the second whitespace delimited field and to further sort
568+
lines with equal keys lexicographically on the first whitespace
569+
delimited field, use:
570+
.Bd -literal -offset indent
571+
$ sort -k 2.2n -k 1 <<EOF
572+
ab X42
573+
aa Y42
574+
ac Z43
575+
EOF
576+
aa Y42
577+
ab X42
578+
ac Z43
579+
.Ed
544580
.Pp
545581
To lexicographically sort the lines of a file in reverse order, use:
546582
.Pp

0 commit comments

Comments
 (0)