|
| 1 | +.\"- |
| 2 | +.\" SPDX-License-Identifier: BSD-2-Clause |
| 3 | +.\" |
| 4 | +.\" Copyright (c) 2026 The MidnightBSD Project |
| 5 | +.\" |
| 6 | +.\" Redistribution and use in source and binary forms, with or without |
| 7 | +.\" modification, are permitted provided that the following conditions |
| 8 | +.\" are met: |
| 9 | +.\" 1. Redistributions of source code must retain the above copyright |
| 10 | +.\" notice, this list of conditions and the following disclaimer. |
| 11 | +.\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | +.\" notice, this list of conditions and the following disclaimer in the |
| 13 | +.\" documentation and/or other materials provided with the distribution. |
| 14 | +.\" |
| 15 | +.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
| 16 | +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
| 19 | +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 20 | +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 21 | +.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 22 | +.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 23 | +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 24 | +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 25 | +.\" SUCH DAMAGE. |
| 26 | +.\" |
| 27 | +.Dd July 10, 2026 |
| 28 | +.Dt NUMFMT 1 |
| 29 | +.Os |
| 30 | +.Sh NAME |
| 31 | +.Nm numfmt |
| 32 | +.Nd convert numbers to or from human-readable form |
| 33 | +.Sh SYNOPSIS |
| 34 | +.Nm |
| 35 | +.Op Fl z |
| 36 | +.Op Fl d Ar char |
| 37 | +.Op Fl f Ar field |
| 38 | +.Op Fl -from Ns = Ns Ar unit |
| 39 | +.Op Fl -to Ns = Ns Ar unit |
| 40 | +.Op Fl -header Ns Op = Ns Ar lines |
| 41 | +.Op Fl -invalid Ns = Ns Ar mode |
| 42 | +.Op Fl -padding Ns = Ns Ar width |
| 43 | +.Op Fl -round Ns = Ns Ar method |
| 44 | +.Op Fl -suffix Ns = Ns Ar suffix |
| 45 | +.Op Ar number ... |
| 46 | +.Sh DESCRIPTION |
| 47 | +The |
| 48 | +.Nm |
| 49 | +utility converts numbers between plain numeric and human-readable forms. |
| 50 | +It provides a BSD-licensed subset of the GNU |
| 51 | +.Nm |
| 52 | +interface commonly used by scripts. |
| 53 | +.Pp |
| 54 | +If |
| 55 | +.Ar number |
| 56 | +operands are specified, each operand is converted and printed on its own line. |
| 57 | +Otherwise, |
| 58 | +.Nm |
| 59 | +reads standard input and converts the selected field on each input line. |
| 60 | +.Pp |
| 61 | +The options are as follows: |
| 62 | +.Bl -tag -width Ds |
| 63 | +.It Fl d Ar char , Fl -delimiter Ns = Ns Ar char |
| 64 | +Use |
| 65 | +.Ar char |
| 66 | +as the input field delimiter instead of blank-separated fields. |
| 67 | +.It Fl f Ar field , Fl -field Ns = Ns Ar field |
| 68 | +Convert the numbered input field. |
| 69 | +The first field is field 1. |
| 70 | +.It Fl -format Ns = Ns Ar format |
| 71 | +Use |
| 72 | +.Ar format |
| 73 | +as a |
| 74 | +.Xr printf 3 |
| 75 | +format string when no output scaling is requested. |
| 76 | +.It Fl -from Ns = Ns Ar unit |
| 77 | +Scale input numbers from |
| 78 | +.Ar unit . |
| 79 | +Supported values are |
| 80 | +.Cm none , |
| 81 | +.Cm auto , |
| 82 | +.Cm si , |
| 83 | +.Cm iec , |
| 84 | +and |
| 85 | +.Cm iec-i . |
| 86 | +.It Fl -header Ns Op = Ns Ar lines |
| 87 | +Copy the first |
| 88 | +.Ar lines |
| 89 | +input lines without conversion. |
| 90 | +If |
| 91 | +.Ar lines |
| 92 | +is omitted, one header line is copied. |
| 93 | +.It Fl -invalid Ns = Ns Ar mode |
| 94 | +Control invalid-number handling. |
| 95 | +Supported modes are |
| 96 | +.Cm abort , |
| 97 | +.Cm fail , |
| 98 | +.Cm warn , |
| 99 | +and |
| 100 | +.Cm ignore . |
| 101 | +.It Fl -padding Ns = Ns Ar width |
| 102 | +Pad converted output to |
| 103 | +.Ar width |
| 104 | +columns. |
| 105 | +Positive values right-align and negative values left-align. |
| 106 | +.It Fl -round Ns = Ns Ar method |
| 107 | +Use the specified rounding method. |
| 108 | +Supported methods are |
| 109 | +.Cm nearest , |
| 110 | +.Cm up , |
| 111 | +.Cm down , |
| 112 | +.Cm from-zero , |
| 113 | +and |
| 114 | +.Cm towards-zero . |
| 115 | +.It Fl -suffix Ns = Ns Ar suffix |
| 116 | +Strip |
| 117 | +.Ar suffix |
| 118 | +from input numbers and append it to scaled output numbers. |
| 119 | +.It Fl -to Ns = Ns Ar unit |
| 120 | +Scale output numbers to |
| 121 | +.Ar unit . |
| 122 | +Supported values are |
| 123 | +.Cm none , |
| 124 | +.Cm si , |
| 125 | +.Cm iec , |
| 126 | +and |
| 127 | +.Cm iec-i . |
| 128 | +Scaled output is formatted with |
| 129 | +.Xr humanize_number 3 . |
| 130 | +.It Fl z , Fl -zero-terminated |
| 131 | +Use NUL instead of newline as the input and output record separator. |
| 132 | +.El |
| 133 | +.Sh EXIT STATUS |
| 134 | +.Ex -std |
| 135 | +.Sh EXAMPLES |
| 136 | +.Dl $ numfmt --to=si 1500 |
| 137 | +.Dl 1.5k |
| 138 | +.Pp |
| 139 | +.Dl $ numfmt --from=iec --to=si 1K |
| 140 | +.Dl 1.1k |
| 141 | +.Sh SEE ALSO |
| 142 | +.Xr humanize_number 3 |
| 143 | +.Sh CAVEATS |
| 144 | +The |
| 145 | +.Nm |
| 146 | +utility implements the GNU options listed above. |
| 147 | +It is not a complete implementation of every GNU |
| 148 | +.Nm |
| 149 | +extension. |
0 commit comments