|
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 $ |
2 | 2 | .\" |
3 | 3 | .\" Copyright (c) 2000-2003 The NetBSD Foundation, Inc. |
4 | 4 | .\" All rights reserved. |
|
59 | 59 | .\" |
60 | 60 | .\" @(#)sort.1 8.1 (Berkeley) 6/6/93 |
61 | 61 | .\" |
62 | | -.Dd January 18, 2026 |
| 62 | +.Dd January 23, 2026 |
63 | 63 | .Dt SORT 1 |
64 | 64 | .Os |
65 | 65 | .Sh NAME |
@@ -524,23 +524,59 @@ use: |
524 | 524 | .Pp |
525 | 525 | .Dl $ sort -m file1 file2 file3 |
526 | 526 | .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 |
530 | 539 | .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 |
532 | 552 | .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 |
536 | 565 | .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 |
544 | 580 | .Pp |
545 | 581 | To lexicographically sort the lines of a file in reverse order, use: |
546 | 582 | .Pp |
|
0 commit comments