logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

sort.1p (23063B)


  1. '\" et
  2. .TH SORT "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. sort
  12. \(em sort, merge, or sequence check text files
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. sort \fB[\fR-m\fB] [\fR-o \fIoutput\fB] [\fR-bdfinru\fB] [\fR-t \fIchar\fB] [\fR-k \fIkeydef\fB]\fR... \fB[\fIfile\fR...\fB]\fR
  17. .P
  18. sort \fB[\fR-c|-C\fB] [\fR-bdfinru\fB] [\fR-t \fIchar\fB] [\fR-k \fIkeydef\fB] [\fIfile\fB]\fR
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. .IR sort
  23. utility shall perform one of the following functions:
  24. .IP " 1." 4
  25. Sort lines of all the named files together and write the result to
  26. the specified output.
  27. .IP " 2." 4
  28. Merge lines of all the named (presorted) files together and write the
  29. result to the specified output.
  30. .IP " 3." 4
  31. Check that a single input file is correctly presorted.
  32. .P
  33. Comparisons shall be based on one or more sort keys extracted from each
  34. line of input (or, if no sort keys are specified, the entire line up
  35. to, but not including, the terminating
  36. <newline>),
  37. and shall be performed using the collating sequence of the current
  38. locale. If this collating sequence does not have a total ordering of
  39. all characters (see the Base Definitions volume of POSIX.1\(hy2017,
  40. .IR "Section 7.3.2" ", " "LC_COLLATE"),
  41. any lines of input that collate equally should be further compared
  42. byte-by-byte using the collating sequence for the POSIX locale.
  43. .SH OPTIONS
  44. The
  45. .IR sort
  46. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  47. .IR "Section 12.2" ", " "Utility Syntax Guidelines",
  48. except for Guideline 9, and the
  49. .BR \-k
  50. .IR keydef
  51. option should follow the
  52. .BR \-b ,
  53. .BR \-d ,
  54. .BR \-f ,
  55. .BR \-i ,
  56. .BR \-n ,
  57. and
  58. .BR \-r
  59. options. In addition,
  60. .BR '\(pl'
  61. may be recognized as an option delimiter as well as
  62. .BR '\-' .
  63. .P
  64. The following options shall be supported:
  65. .IP "\fB\-c\fP" 10
  66. Check that the single input file is ordered as specified by the
  67. arguments and the collating sequence of the current locale. Output
  68. shall not be sent to standard output. The exit code shall indicate
  69. whether or not disorder was detected or an error occurred. If
  70. disorder (or, with
  71. .BR \-u ,
  72. a duplicate key) is detected, a warning message shall be sent to
  73. standard error indicating where the disorder or duplicate key
  74. was found.
  75. .IP "\fB\-C\fP" 10
  76. Same as
  77. .BR \-c ,
  78. except that a warning message shall not be sent to standard error
  79. if disorder or, with
  80. .BR \-u ,
  81. a duplicate key is detected.
  82. .IP "\fB\-m\fP" 10
  83. Merge only; the input file shall be assumed to be already sorted.
  84. .IP "\fB\-o\ \fIoutput\fR" 10
  85. Specify the name of an output file to be used instead of the standard
  86. output. This file can be the same as one of the input
  87. .IR file s.
  88. .IP "\fB\-u\fP" 10
  89. Unique: suppress all but one in each set of lines having equal keys.
  90. If used with the
  91. .BR \-c
  92. option, check that there are no lines with duplicate keys, in addition
  93. to checking that the input file is sorted.
  94. .P
  95. The following options shall override the default ordering rules. When
  96. ordering options appear independent of any key field specifications,
  97. the requested field ordering rules shall be applied globally to all
  98. sort keys. When attached to a specific key (see
  99. .BR \-k ),
  100. the specified ordering options shall override all global ordering
  101. options for that key.
  102. .IP "\fB\-d\fP" 10
  103. Specify that only
  104. <blank>
  105. characters and alphanumeric characters, according to the current
  106. setting of
  107. .IR LC_CTYPE ,
  108. shall be significant in comparisons. The behavior is undefined for a
  109. sort key to which
  110. .BR \-i
  111. or
  112. .BR \-n
  113. also applies.
  114. .IP "\fB\-f\fP" 10
  115. Consider all lowercase characters that have uppercase equivalents,
  116. according to the current setting of
  117. .IR LC_CTYPE ,
  118. to be the uppercase equivalent for the purposes of comparison.
  119. .IP "\fB\-i\fP" 10
  120. Ignore all characters that are non-printable, according to the current
  121. setting of
  122. .IR LC_CTYPE .
  123. The behavior is undefined for a sort key for which
  124. .BR \-n
  125. also applies.
  126. .IP "\fB\-n\fP" 10
  127. Restrict the sort key to an initial numeric string, consisting of
  128. optional
  129. <blank>
  130. characters, optional
  131. <hyphen-minus>
  132. character, and zero or more digits with an
  133. optional radix character and thousands separators (as defined in the
  134. current locale), which shall be sorted by arithmetic value. An empty
  135. digit string shall be treated as zero. Leading zeros and signs on zeros
  136. shall not affect ordering.
  137. .IP "\fB\-r\fP" 10
  138. Reverse the sense of comparisons.
  139. .P
  140. The treatment of field separators can be altered using the options:
  141. .IP "\fB\-b\fP" 10
  142. Ignore leading
  143. <blank>
  144. characters when determining the starting and ending positions of a
  145. restricted sort key. If the
  146. .BR \-b
  147. option is specified before the first
  148. .BR \-k
  149. option, it shall be applied to all
  150. .BR \-k
  151. options. Otherwise, the
  152. .BR \-b
  153. option can be attached independently to each
  154. .BR \-k
  155. .IR field_start
  156. or
  157. .IR field_end
  158. option-argument (see below).
  159. .IP "\fB\-t\ \fIchar\fR" 10
  160. Use
  161. .IR char
  162. as the field separator character;
  163. .IR char
  164. shall not be considered to be part of a field (although it can be
  165. included in a sort key). Each occurrence of
  166. .IR char
  167. shall be significant (for example, <\fIchar\fR><\fIchar\fR> delimits an
  168. empty field). If
  169. .BR \-t
  170. is not specified,
  171. <blank>
  172. characters shall be used as default field separators; each maximal
  173. non-empty sequence of
  174. <blank>
  175. characters that follows a non-\c
  176. <blank>
  177. shall be a field separator.
  178. .P
  179. Sort keys can be specified using the options:
  180. .IP "\fB\-k\ \fIkeydef\fR" 10
  181. The
  182. .IR keydef
  183. argument is a restricted sort key field definition. The format of this
  184. definition is:
  185. .RS 10
  186. .sp
  187. .RS 4
  188. .nf
  189. \fIfield_start\fB[\fItype\fB][\fR,\fIfield_end\fB[\fItype\fB]]\fR
  190. .fi
  191. .P
  192. .RE
  193. .P
  194. where
  195. .IR field_start
  196. and
  197. .IR field_end
  198. define a key field restricted to a portion of the line (see the
  199. EXTENDED DESCRIPTION section), and
  200. .IR type
  201. is one or more modifiers from the list of characters
  202. .BR 'b' ,
  203. .BR 'd' ,
  204. .BR 'f' ,
  205. .BR 'i' ,
  206. .BR 'n' ,
  207. .BR 'r' .
  208. The
  209. .BR 'b'
  210. modifier shall behave like the
  211. .BR \-b
  212. option, but shall apply only to the
  213. .IR field_start
  214. or
  215. .IR field_end
  216. to which it is attached. The other modifiers shall behave like the
  217. corresponding options, but shall apply only to the key field to which
  218. they are attached; they shall have this effect if specified with
  219. .IR field_start ,
  220. .IR field_end ,
  221. or both. If any modifier is attached to a
  222. .IR field_start
  223. or to a
  224. .IR field_end ,
  225. no option shall apply to either. Implementations shall support at
  226. least nine occurrences of the
  227. .BR \-k
  228. option, which shall be significant in command line order. If no
  229. .BR \-k
  230. option is specified, a default sort key of the entire line shall be
  231. used.
  232. .P
  233. When there are multiple key fields, later keys shall be compared only
  234. after all earlier keys compare equal. Except when the
  235. .BR \-u
  236. option is specified, lines that otherwise compare equal shall be
  237. ordered as if none of the options
  238. .BR \-d ,
  239. .BR \-f ,
  240. .BR \-i ,
  241. .BR \-n ,
  242. or
  243. .BR \-k
  244. were present (but with
  245. .BR \-r
  246. still in effect, if it was specified) and with all bytes in the lines
  247. significant to the comparison. The order in which lines that still
  248. compare equal are written is unspecified.
  249. .RE
  250. .SH OPERANDS
  251. The following operand shall be supported:
  252. .IP "\fIfile\fR" 10
  253. A pathname of a file to be sorted, merged, or checked. If no
  254. .IR file
  255. operands are specified, or if a
  256. .IR file
  257. operand is
  258. .BR '\-' ,
  259. the standard input shall be used. If
  260. .IR sort
  261. encounters an error when opening or reading a
  262. .IR file
  263. operand, it may exit without writing any output to standard output or
  264. processing later operands.
  265. .SH STDIN
  266. The standard input shall be used only if no
  267. .IR file
  268. operands are specified, or if a
  269. .IR file
  270. operand is
  271. .BR '\-' .
  272. See the INPUT FILES section.
  273. .SH "INPUT FILES"
  274. The input files shall be text files, except that the
  275. .IR sort
  276. utility shall add a
  277. <newline>
  278. to the end of a file ending with an incomplete last line.
  279. .SH "ENVIRONMENT VARIABLES"
  280. The following environment variables shall affect the execution of
  281. .IR sort :
  282. .IP "\fILANG\fP" 10
  283. Provide a default value for the internationalization variables that are
  284. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  285. .IR "Section 8.2" ", " "Internationalization Variables"
  286. for the precedence of internationalization variables used to determine
  287. the values of locale categories.)
  288. .IP "\fILC_ALL\fP" 10
  289. If set to a non-empty string value, override the values of all the
  290. other internationalization variables.
  291. .IP "\fILC_COLLATE\fP" 10
  292. .br
  293. Determine the locale for ordering rules.
  294. .IP "\fILC_CTYPE\fP" 10
  295. Determine the locale for the interpretation of sequences of bytes of
  296. text data as characters (for example, single-byte as opposed to
  297. multi-byte characters in arguments and input files) and the behavior of
  298. character classification for the
  299. .BR \-b ,
  300. .BR \-d ,
  301. .BR \-f ,
  302. .BR \-i ,
  303. and
  304. .BR \-n
  305. options.
  306. .IP "\fILC_MESSAGES\fP" 10
  307. .br
  308. Determine the locale that should be used to affect the format and
  309. contents of diagnostic messages written to standard error.
  310. .IP "\fILC_NUMERIC\fP" 10
  311. .br
  312. Determine the locale for the definition of the radix character and
  313. thousands separator for the
  314. .BR \-n
  315. option.
  316. .IP "\fINLSPATH\fP" 10
  317. Determine the location of message catalogs for the processing of
  318. .IR LC_MESSAGES .
  319. .SH "ASYNCHRONOUS EVENTS"
  320. Default.
  321. .SH STDOUT
  322. Unless the
  323. .BR \-o
  324. or
  325. .BR \-c
  326. options are in effect, the standard output shall contain the sorted
  327. input.
  328. .SH STDERR
  329. The standard error shall be used for diagnostic messages. When
  330. .BR \-c
  331. is specified, if disorder is detected (or if
  332. .BR \-u
  333. is also specified and a duplicate key is detected), a message shall
  334. be written to the standard error which identifies the input line at
  335. which disorder (or a duplicate key) was detected. A warning
  336. message about correcting an incomplete last line of an input file
  337. may be generated, but need not affect the final exit status.
  338. .SH "OUTPUT FILES"
  339. If the
  340. .BR \-o
  341. option is in effect, the sorted input shall be written to the file
  342. .IR output .
  343. .SH "EXTENDED DESCRIPTION"
  344. The notation:
  345. .sp
  346. .RS 4
  347. .nf
  348. -k \fIfield_start\fB[\fItype\fB][\fR,\fIfield_end\fB[\fItype\fB]]\fR
  349. .fi
  350. .P
  351. .RE
  352. .P
  353. shall define a key field that begins at
  354. .IR field_start
  355. and ends at
  356. .IR field_end
  357. inclusive, unless
  358. .IR field_start
  359. falls beyond the end of the line or after
  360. .IR field_end ,
  361. in which case the key field is empty. A missing
  362. .IR field_end
  363. shall mean the last character of the line.
  364. .P
  365. A field comprises a maximal sequence of non-separating characters and,
  366. in the absence of option
  367. .BR \-t ,
  368. any preceding field separator.
  369. .P
  370. The
  371. .IR field_start
  372. portion of the
  373. .IR keydef
  374. option-argument shall have the form:
  375. .sp
  376. .RS 4
  377. .nf
  378. \fIfield_number\fB[\fR.\fIfirst_character\fB]\fR
  379. .fi
  380. .P
  381. .RE
  382. .P
  383. Fields and characters within fields shall be numbered starting with 1.
  384. The
  385. .IR field_number
  386. and
  387. .IR first_character
  388. pieces, interpreted as positive decimal integers, shall specify the
  389. first character to be used as part of a sort key. If
  390. .IR .first_character
  391. is omitted, it shall refer to the first character of the field.
  392. .P
  393. The
  394. .IR field_end
  395. portion of the
  396. .IR keydef
  397. option-argument shall have the form:
  398. .sp
  399. .RS 4
  400. .nf
  401. \fIfield_number\fB[\fR.\fIlast_character\fB]\fR
  402. .fi
  403. .P
  404. .RE
  405. .P
  406. The
  407. .IR field_number
  408. shall be as described above for
  409. .IR field_start.
  410. The
  411. .IR last_character
  412. piece, interpreted as a non-negative decimal integer, shall specify the
  413. last character to be used as part of the sort key. If
  414. .IR last_character
  415. evaluates to zero or
  416. .IR .last_character
  417. is omitted, it shall refer to the last character of the field specified
  418. by
  419. .IR field_number .
  420. .P
  421. If the
  422. .BR \-b
  423. option or
  424. .BR b
  425. type modifier is in effect, characters within a field shall be counted
  426. from the first non-\c
  427. <blank>
  428. in the field. (This shall apply separately to
  429. .IR first_character
  430. and
  431. .IR last_character .)
  432. .SH "EXIT STATUS"
  433. The following exit values shall be returned:
  434. .IP "\00" 6
  435. All input files were output successfully, or
  436. .BR \-c
  437. was specified and the input file was correctly sorted.
  438. .IP "\01" 6
  439. Under the
  440. .BR \-c
  441. option, the file was not ordered as specified, or if the
  442. .BR \-c
  443. and
  444. .BR \-u
  445. options were both specified, two input lines were found with equal
  446. keys.
  447. .IP >1 6
  448. An error occurred.
  449. .SH "CONSEQUENCES OF ERRORS"
  450. The default requirements shall apply, except that if
  451. .IR sort
  452. encounters an error when opening or reading a
  453. .IR file
  454. operand, it may exit without writing any output to standard output or
  455. processing later operands.
  456. .LP
  457. .IR "The following sections are informative."
  458. .SH "APPLICATION USAGE"
  459. The default value for
  460. .BR \-t ,
  461. <blank>,
  462. has different properties from, for example,
  463. .BR \-t \c
  464. "<space>". If a line contains:
  465. .sp
  466. .RS 4
  467. .nf
  468. <space><space>foo
  469. .fi
  470. .P
  471. .RE
  472. .P
  473. the following treatment would occur with default separation as opposed
  474. to specifically selecting a
  475. <space>:
  476. .TS
  477. center box tab(@);
  478. cB | cB | cB
  479. n | l | l.
  480. Field@Default@\-t "<space>"
  481. _
  482. 1@<space><space>foo@\fIempty\fP
  483. 2@\fIempty\fP@\fIempty\fP
  484. 3@\fIempty\fP@foo
  485. .TE
  486. .P
  487. The leading field separator itself is included in a field when
  488. .BR \-t
  489. is not used. For example, this command returns an exit status of zero,
  490. meaning the input was already sorted:
  491. .sp
  492. .RS 4
  493. .nf
  494. sort -c -k 2 <<eof
  495. y<tab>b
  496. x<space>a
  497. eof
  498. .fi
  499. .P
  500. .RE
  501. .P
  502. (assuming that a
  503. <tab>
  504. precedes the
  505. <space>
  506. in the current collating sequence). The field separator is not included
  507. in a field when it is explicitly set via
  508. .BR \-t .
  509. This is historical practice and allows usage such as:
  510. .sp
  511. .RS 4
  512. .nf
  513. sort -t "|" -k 2n <<eof
  514. Atlanta|425022|Georgia
  515. Birmingham|284413|Alabama
  516. Columbia|100385|South Carolina
  517. eof
  518. .fi
  519. .P
  520. .RE
  521. .P
  522. where the second field can be correctly sorted numerically without
  523. regard to the non-numeric field separator.
  524. .P
  525. The wording in the OPTIONS section clarifies that the
  526. .BR \-b ,
  527. .BR \-d ,
  528. .BR \-f ,
  529. .BR \-i ,
  530. .BR \-n ,
  531. and
  532. .BR \-r
  533. options have to come before the first sort key specified if they are
  534. intended to apply to all specified keys. The way it is described in
  535. \&this volume of POSIX.1\(hy2017 matches historical practice, not historical documentation.
  536. The results are unspecified if these options are specified after a
  537. .BR \-k
  538. option.
  539. .P
  540. The
  541. .BR \-f
  542. option might not work as expected in locales where there is not a
  543. one-to-one mapping between an uppercase and a lowercase letter.
  544. .P
  545. When using
  546. .IR sort
  547. to process pathnames, it is recommended that LC_ALL, or at least
  548. LC_CTYPE and LC_COLLATE, are set to POSIX or C in the environment,
  549. since pathnames can contain byte sequences that do not form valid
  550. characters in some locales, in which case the utility's behavior would
  551. be undefined. In the POSIX locale each byte is a valid single-byte
  552. character, and therefore this problem is avoided.
  553. .P
  554. If the collating sequence of the current locale does not have a total
  555. ordering of all characters, this can affect the behavior of
  556. .IR sort
  557. in the following ways:
  558. .IP " *" 4
  559. As
  560. .IR sort
  561. .BR \-u
  562. suppresses lines with duplicate keys, it suppresses lines that collate
  563. equally but are not identical.
  564. .IP " *" 4
  565. The output of
  566. .IR sort
  567. (without
  568. .BR \-u )
  569. can contain identical lines that are not adjacent, if it does not
  570. implement the recommended further byte-by-byte comparison of lines
  571. that collate equally. This affects the use of
  572. .IR sort
  573. with
  574. .IR comm
  575. and
  576. .IR uniq ;
  577. see the APPLICATION USAGE for those utilities.
  578. .SH EXAMPLES
  579. .IP " 1." 4
  580. The following command sorts the contents of
  581. .BR infile
  582. with the second field as the sort key:
  583. .RS 4
  584. .sp
  585. .RS 4
  586. .nf
  587. sort -k 2,2 infile
  588. .fi
  589. .P
  590. .RE
  591. .RE
  592. .IP " 2." 4
  593. The following command sorts, in reverse order, the contents of
  594. .BR infile1
  595. and
  596. .BR infile2 ,
  597. placing the output in
  598. .BR outfile
  599. and using the second character of the second field as the sort key
  600. (assuming that the first character of the second field is the field
  601. separator):
  602. .RS 4
  603. .sp
  604. .RS 4
  605. .nf
  606. sort -r -o outfile -k 2.2,2.2 infile1 infile2
  607. .fi
  608. .P
  609. .RE
  610. .RE
  611. .IP " 3." 4
  612. The following command sorts the contents of
  613. .BR infile1
  614. and
  615. .BR infile2
  616. using the second non-\c
  617. <blank>
  618. of the second field as the sort key:
  619. .RS 4
  620. .sp
  621. .RS 4
  622. .nf
  623. sort -k 2.2b,2.2b infile1 infile2
  624. .fi
  625. .P
  626. .RE
  627. .RE
  628. .IP " 4." 4
  629. The following command prints the System\ V password file (user
  630. database) sorted by the numeric user ID (the third
  631. <colon>-separated
  632. field):
  633. .RS 4
  634. .sp
  635. .RS 4
  636. .nf
  637. sort -t : -k 3,3n /etc/passwd
  638. .fi
  639. .P
  640. .RE
  641. .RE
  642. .IP " 5." 4
  643. The following command prints the lines of the already sorted file
  644. .BR infile ,
  645. suppressing all but one occurrence of lines having the same third
  646. field:
  647. .RS 4
  648. .sp
  649. .RS 4
  650. .nf
  651. sort -um -k 3.1,3.0 infile
  652. .fi
  653. .P
  654. .RE
  655. .RE
  656. .SH RATIONALE
  657. Examples in some historical documentation state that options
  658. .BR \-um
  659. with one input file keep the first in each set of lines with equal
  660. keys. This behavior was deemed to be an implementation artifact and
  661. was not standardized.
  662. .P
  663. The
  664. .BR \-z
  665. option was omitted; it is not standard practice on most systems and is
  666. inconsistent with using
  667. .IR sort
  668. to sort several files individually and then merge them together. The
  669. text concerning
  670. .BR \-z
  671. in historical documentation appeared to require implementations to
  672. determine the proper buffer length during the sort phase of operation,
  673. but not during the merge.
  674. .P
  675. The
  676. .BR \-y
  677. option was omitted because of non-portability. The
  678. .BR \-M
  679. option, present in System V, was omitted because of non-portability in
  680. international usage.
  681. .P
  682. An undocumented
  683. .BR \-T
  684. option exists in some implementations. It is used to specify a
  685. directory for intermediate files. Implementations are encouraged to
  686. support the use of the
  687. .IR TMPDIR
  688. environment variable instead of adding an option to support this
  689. functionality.
  690. .P
  691. The
  692. .BR \-k
  693. option was added to satisfy two objections. First, the zero-based
  694. counting used by
  695. .IR sort
  696. is not consistent with other utility conventions. Second, it did not
  697. meet syntax guideline requirements.
  698. .P
  699. Historical documentation indicates that ``setting
  700. .BR \-n
  701. implies
  702. .BR \-b ''.
  703. The description of
  704. .BR \-n
  705. already states that optional leading <blank>s are tolerated in doing
  706. the comparison. If
  707. .BR \-b
  708. is enabled, rather than implied, by
  709. .BR \-n ,
  710. this has unusual side-effects. When a character offset is used in a
  711. column of numbers (for example, to sort modulo 100), that offset is
  712. measured relative to the most significant digit, not to the column.
  713. Based upon a recommendation from the author of the original
  714. .IR sort
  715. utility, the
  716. .BR \-b
  717. implication has been omitted from this volume of POSIX.1\(hy2017, and an application wishing to
  718. achieve the previously mentioned side-effects has to code the
  719. .BR \-b
  720. flag explicitly.
  721. .P
  722. Earlier versions of this standard allowed the
  723. .BR \-o
  724. option to appear after operands. Historical practice allowed all
  725. options to be interspersed with operands. This version of the
  726. standard allows implementations to accept options after operands
  727. but conforming applications should not use this form.
  728. .P
  729. Earlier versions of this standard also allowed the
  730. .BR \- \c
  731. .IR number
  732. and
  733. .BR \(pl \c
  734. .IR number
  735. options. These options are no longer specified by POSIX.1\(hy2008 but may
  736. be present in some implementations.
  737. .P
  738. Historical implementations produced a message on standard error when
  739. .BR \-c
  740. was specified and disorder was detected, and when
  741. .BR \-c
  742. and
  743. .BR \-u
  744. were specified and a duplicate key was detected. An earlier version of
  745. this standard contained wording that did not make it clear that this
  746. message was allowed and some implementations removed this message to
  747. be sure that they conformed to the standard's requirements. Confronted
  748. with this difference in behavior, interactive users that wanted to be
  749. sure that they got visual feedback instead of just exit code 1 could
  750. have used a command like:
  751. .sp
  752. .RS 4
  753. .nf
  754. sort -c file || echo disorder
  755. .fi
  756. .P
  757. .RE
  758. .P
  759. whether or not the
  760. .IR sort
  761. utility provided a message in this case. But, it was not easy for a user
  762. to find where the disorder or duplicate key occurred on implementations
  763. that do not produce a message, especially when some parts of the input
  764. line were not part of the key and when one or more of the
  765. .BR \-b ,
  766. .BR \-d ,
  767. .BR \-f ,
  768. .BR \-i ,
  769. .BR \-n ,
  770. or
  771. .BR \- r
  772. options or
  773. .IR keydef
  774. type modifiers were in use. POSIX.1\(hy2008 requires a message to be
  775. produced in this case. POSIX.1\(hy2008 also contains the
  776. .BR \-C
  777. option giving users the ability to choose either behavior.
  778. .P
  779. When a disorder or duplicate is found when the
  780. .BR \-c
  781. option is specified, some implementations print a message containing
  782. the first line that is out of order or contains a duplicate key; others
  783. print a message specifying the line number of the offending line. This
  784. standard allows either type of message.
  785. .P
  786. Implementations are encouraged to perform the recommended further
  787. byte-by-byte comparison of lines that collate equally, even though
  788. this may affect efficiency. The impact on efficiency can be mitigated
  789. by only performing the additional comparison if the current locale's
  790. collating sequence does not have a total ordering of all characters
  791. (if the implementation provides a way to query this) or by only
  792. performing the additional comparison if the locale name associated
  793. with the LC_COLLATE category has an
  794. .BR '@'
  795. modifier in the name (since locales without an
  796. .BR '@'
  797. modifier should have a total ordering of all characters \(em see the Base Definitions volume of POSIX.1\(hy2017,
  798. .IR "Section 7.3.2" ", " "LC_COLLATE").
  799. Note that if the implementation provides a
  800. .IR "stable sort"
  801. option as an extension (usually
  802. .BR \-s ),
  803. the additional comparison should not be performed when this option has
  804. been specified.
  805. .SH "FUTURE DIRECTIONS"
  806. A future version of this standard may require that if the collating
  807. sequence of the current locale does not have a total ordering of all
  808. characters, any lines of input that collate equally when comparing
  809. them as whole lines are further compared byte-by-byte using the
  810. collating sequence for the POSIX locale.
  811. .SH "SEE ALSO"
  812. .IR "\fIcomm\fR\^",
  813. .IR "\fIjoin\fR\^",
  814. .IR "\fIuniq\fR\^"
  815. .P
  816. The Base Definitions volume of POSIX.1\(hy2017,
  817. .IR "Section 7.3.2" ", " "LC_COLLATE",
  818. .IR "Chapter 8" ", " "Environment Variables",
  819. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  820. .P
  821. The System Interfaces volume of POSIX.1\(hy2017,
  822. .IR "\fItoupper\fR\^(\|)"
  823. .\"
  824. .SH COPYRIGHT
  825. Portions of this text are reprinted and reproduced in electronic form
  826. from IEEE Std 1003.1-2017, Standard for Information Technology
  827. -- Portable Operating System Interface (POSIX), The Open Group Base
  828. Specifications Issue 7, 2018 Edition,
  829. Copyright (C) 2018 by the Institute of
  830. Electrical and Electronics Engineers, Inc and The Open Group.
  831. In the event of any discrepancy between this version and the original IEEE and
  832. The Open Group Standard, the original IEEE and The Open Group Standard
  833. is the referee document. The original Standard can be obtained online at
  834. http://www.opengroup.org/unix/online.html .
  835. .PP
  836. Any typographical or formatting errors that appear
  837. in this page are most likely
  838. to have been introduced during the conversion of the source files to
  839. man page format. To report such errors, see
  840. https://www.kernel.org/doc/man-pages/reporting_bugs.html .