xref: /freebsd/usr.bin/jot/jot.1 (revision 02e9120893770924227138ba49df1edb3896112a)
1.\" Copyright (c) 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd September 21, 2019
29.Dt JOT 1
30.Os
31.Sh NAME
32.Nm jot
33.Nd print sequential or random data
34.Sh SYNOPSIS
35.Nm
36.Op Fl cnr
37.Op Fl b Ar word
38.Op Fl w Ar word
39.Op Fl s Ar string
40.Op Fl p Ar precision
41.Op Ar reps Op Ar begin Op Ar end Op Ar s
42.Sh DESCRIPTION
43The
44.Nm
45utility is used to print out increasing, decreasing, random,
46or redundant data, usually numbers, one per line.
47.Pp
48The following options are available:
49.Bl -tag -width indent
50.It Fl r
51Generate random data instead of the default sequential data.
52.It Fl b Ar word
53Just print
54.Ar word
55repetitively.
56.It Fl w Ar word
57Print
58.Ar word
59with the generated data appended to it.
60Octal, hexadecimal, exponential,
61.Tn ASCII ,
62zero padded,
63and right-adjusted representations
64are possible by using the appropriate
65.Xr printf 3
66conversion specification inside
67.Ar word ,
68in which case the data are inserted rather than appended.
69.It Fl c
70This is an abbreviation for
71.Fl w Ar %c .
72.It Fl s Ar string
73Print data separated by
74.Ar string .
75Normally, newlines separate data.
76.It Fl n
77Do not print the final newline normally appended to the output.
78.It Fl p Ar precision
79Print only as many digits or characters of the data
80as indicated by the integer
81.Ar precision .
82In the absence of
83.Fl p ,
84the precision is the greater of the precisions of
85.Ar begin
86and
87.Ar end .
88The
89.Fl p
90option is overridden by whatever appears in a
91.Xr printf 3
92conversion following
93.Fl w .
94.El
95.Pp
96The last four arguments indicate, respectively,
97the number of data, the lower bound, the upper bound,
98and the step size or, for random data, the seed.
99While at least one of them must appear,
100any of the other three may be omitted, and
101will be considered as such if given as
102.Fl ""
103or as an empty string.
104Any three of these arguments determines the fourth.
105If four are specified and the given and computed values of
106.Ar reps
107conflict, the lower value is used.
108If one or two are specified, defaults are assigned
109starting with
110.Ar s ,
111which assumes a default of 1 (or -1 if
112.Ar begin
113and
114.Ar end
115specify a descending range).
116Then the default values are assigned to the leftmost omitted arguments until
117three arguments are set.
118.Pp
119Defaults for the four arguments are, respectively,
120100, 1, 100, and 1, except that when random data are requested,
121the seed,
122.Ar s ,
123is picked randomly.
124The
125.Ar reps
126argument is expected to be an unsigned integer,
127and if given as zero is taken to be infinite.
128The
129.Ar begin
130and
131.Ar end
132arguments may be given as real numbers or as characters
133representing the corresponding value in
134.Tn ASCII .
135The last argument must be a real number.
136.Pp
137Random numbers are obtained through
138.Xr arc4random 3
139when no seed is specified,
140and through
141.Xr random 3
142when a seed is given.
143When
144.Nm
145is asked to generate random integers or characters with begin
146and end values in the range of the random number generator function
147and no format is specified with one of the
148.Fl w ,
149.Fl b ,
150or
151.Fl p
152options,
153.Nm
154will arrange for all the values in the range to appear in the output
155with an equal probability.
156In all other cases be careful to ensure that the output format's
157rounding or truncation will not skew the distribution of output
158values in an unintended way.
159.Pp
160The name
161.Nm
162derives in part from
163.Nm iota ,
164a function in APL.
165.Ss Rounding and truncation
166The
167.Nm
168utility uses double precision floating point arithmetic internally.
169Before printing a number, it is converted depending on the output
170format used.
171.Pp
172If no output format is specified or the output format is a
173floating point format
174.Po
175.Sq E ,
176.Sq G ,
177.Sq e ,
178.Sq f ,
179or
180.Sq g
181.Pc ,
182the value is rounded using the
183.Xr printf 3
184function, taking into account the requested precision.
185.Pp
186If the output format is an integer format
187.Po
188.Sq D ,
189.Sq O ,
190.Sq U ,
191.Sq X ,
192.Sq c ,
193.Sq d ,
194.Sq i ,
195.Sq o ,
196.Sq u ,
197or
198.Sq x
199.Pc ,
200the value is converted to an integer value by truncation.
201.Pp
202As an illustration, consider the following command:
203.Bd -literal -offset indent
204$ jot 6 1 10 0.5
2051
2062
2072
2082
2093
2104
211.Ed
212.Pp
213By requesting an explicit precision of 1, the values generated before rounding
214can be seen.
215The .5 values are rounded down if the integer part is even,
216up otherwise.
217.Bd -literal -offset indent
218$ jot -p 1 6 1 10 0.5
2191.0
2201.5
2212.0
2222.5
2233.0
2243.5
225.Ed
226.Pp
227By offsetting the values slightly, the values generated by the following
228command are always rounded down:
229.Bd -literal -offset indent
230$ jot -p 0 6 .9999999999 10 0.5
2311
2321
2332
2342
2353
2363
237.Ed
238.Pp
239Another way of achieving the same result is to force truncation by
240specifying an integer format:
241.Bd -literal -offset indent
242$ jot -w %d 6 1 10 0.5
243.Ed
244.Sh EXIT STATUS
245.Ex -std
246.Sh EXAMPLES
247The command
248.Dl jot - 1 10
249.Pp
250prints the integers from 1 to 10,
251while the command
252.Dl jot 21 -1 1.00
253.Pp
254prints 21 evenly spaced numbers increasing from -1 to 1.
255The
256.Tn ASCII
257character set is generated with
258.Dl jot -c 128 0
259.Pp
260and the strings xaa through xaz with
261.Dl jot -w xa%c 26 a
262.Pp
263while 20 random 8-letter strings are produced with
264.Dl "jot -r -c 160 a z | rs -g 0 8"
265.Pp
266Infinitely many
267.Em yes Ns 's
268may be obtained through
269.Dl jot -b yes 0
270.Pp
271and thirty
272.Xr ed 1
273substitution commands applying to lines 2, 7, 12, etc.\& is
274the result of
275.Dl jot -w %ds/old/new/ 30 2 - 5
276.Pp
277The stuttering sequence 9, 9, 8, 8, 7, etc.\& can be
278produced by truncating the output precision and a suitable choice of step size,
279as in
280.Dl jot -w %d - 9.5 0 -.5
281.Pp
282and a file containing exactly 1024 bytes is created with
283.Dl jot -b x 512 > block
284.Pp
285Finally, to set tabs four spaces apart starting
286from column 10 and ending in column 132, use
287.Dl expand -`jot -s, - 10 132 4`
288.Pp
289and to print all lines 80 characters or longer,
290.Dl grep `jot -s \&"\&" -b \&. 80`
291.Sh DIAGNOSTICS
292The following diagnostic messages deserve special explanation:
293.Bl -diag
294.It "illegal or unsupported format '%s'"
295The requested conversion format specifier for
296.Xr printf 3
297was not of the form
298.Dl %[#][ ][{+,-}][0-9]*[.[0-9]*]?
299where
300.Dq ?\&
301must be one of
302.Dl [l]{d,i,o,u,x}
303or
304.Dl {c,e,f,g,D,E,G,O,U,X}
305.It "range error in conversion"
306A value to be printed fell outside the range of the data type
307associated with the requested output format.
308.It "too many conversions"
309More than one conversion format specifier has been supplied,
310but only one is allowed.
311.El
312.Sh SEE ALSO
313.Xr ed 1 ,
314.Xr expand 1 ,
315.Xr rs 1 ,
316.Xr seq 1 ,
317.Xr yes 1 ,
318.Xr arc4random 3 ,
319.Xr printf 3 ,
320.Xr random 3
321.Sh HISTORY
322The
323.Nm
324utility first appeared in
325.Bx 4.2 .
326.Sh AUTHORS
327.An John A. Kunze
328