xref: /freebsd/usr.bin/jot/jot.1 (revision 2008043f386721d58158e37e0d7e50df8095942d)
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.\"	@(#)jot.1	8.1 (Berkeley) 6/6/93
29.\"
30.Dd September 21, 2019
31.Dt JOT 1
32.Os
33.Sh NAME
34.Nm jot
35.Nd print sequential or random data
36.Sh SYNOPSIS
37.Nm
38.Op Fl cnr
39.Op Fl b Ar word
40.Op Fl w Ar word
41.Op Fl s Ar string
42.Op Fl p Ar precision
43.Op Ar reps Op Ar begin Op Ar end Op Ar s
44.Sh DESCRIPTION
45The
46.Nm
47utility is used to print out increasing, decreasing, random,
48or redundant data, usually numbers, one per line.
49.Pp
50The following options are available:
51.Bl -tag -width indent
52.It Fl r
53Generate random data instead of the default sequential data.
54.It Fl b Ar word
55Just print
56.Ar word
57repetitively.
58.It Fl w Ar word
59Print
60.Ar word
61with the generated data appended to it.
62Octal, hexadecimal, exponential,
63.Tn ASCII ,
64zero padded,
65and right-adjusted representations
66are possible by using the appropriate
67.Xr printf 3
68conversion specification inside
69.Ar word ,
70in which case the data are inserted rather than appended.
71.It Fl c
72This is an abbreviation for
73.Fl w Ar %c .
74.It Fl s Ar string
75Print data separated by
76.Ar string .
77Normally, newlines separate data.
78.It Fl n
79Do not print the final newline normally appended to the output.
80.It Fl p Ar precision
81Print only as many digits or characters of the data
82as indicated by the integer
83.Ar precision .
84In the absence of
85.Fl p ,
86the precision is the greater of the precisions of
87.Ar begin
88and
89.Ar end .
90The
91.Fl p
92option is overridden by whatever appears in a
93.Xr printf 3
94conversion following
95.Fl w .
96.El
97.Pp
98The last four arguments indicate, respectively,
99the number of data, the lower bound, the upper bound,
100and the step size or, for random data, the seed.
101While at least one of them must appear,
102any of the other three may be omitted, and
103will be considered as such if given as
104.Fl ""
105or as an empty string.
106Any three of these arguments determines the fourth.
107If four are specified and the given and computed values of
108.Ar reps
109conflict, the lower value is used.
110If one or two are specified, defaults are assigned
111starting with
112.Ar s ,
113which assumes a default of 1 (or -1 if
114.Ar begin
115and
116.Ar end
117specify a descending range).
118Then the default values are assigned to the leftmost omitted arguments until
119three arguments are set.
120.Pp
121Defaults for the four arguments are, respectively,
122100, 1, 100, and 1, except that when random data are requested,
123the seed,
124.Ar s ,
125is picked randomly.
126The
127.Ar reps
128argument is expected to be an unsigned integer,
129and if given as zero is taken to be infinite.
130The
131.Ar begin
132and
133.Ar end
134arguments may be given as real numbers or as characters
135representing the corresponding value in
136.Tn ASCII .
137The last argument must be a real number.
138.Pp
139Random numbers are obtained through
140.Xr arc4random 3
141when no seed is specified,
142and through
143.Xr random 3
144when a seed is given.
145When
146.Nm
147is asked to generate random integers or characters with begin
148and end values in the range of the random number generator function
149and no format is specified with one of the
150.Fl w ,
151.Fl b ,
152or
153.Fl p
154options,
155.Nm
156will arrange for all the values in the range to appear in the output
157with an equal probability.
158In all other cases be careful to ensure that the output format's
159rounding or truncation will not skew the distribution of output
160values in an unintended way.
161.Pp
162The name
163.Nm
164derives in part from
165.Nm iota ,
166a function in APL.
167.Ss Rounding and truncation
168The
169.Nm
170utility uses double precision floating point arithmetic internally.
171Before printing a number, it is converted depending on the output
172format used.
173.Pp
174If no output format is specified or the output format is a
175floating point format
176.Po
177.Sq E ,
178.Sq G ,
179.Sq e ,
180.Sq f ,
181or
182.Sq g
183.Pc ,
184the value is rounded using the
185.Xr printf 3
186function, taking into account the requested precision.
187.Pp
188If the output format is an integer format
189.Po
190.Sq D ,
191.Sq O ,
192.Sq U ,
193.Sq X ,
194.Sq c ,
195.Sq d ,
196.Sq i ,
197.Sq o ,
198.Sq u ,
199or
200.Sq x
201.Pc ,
202the value is converted to an integer value by truncation.
203.Pp
204As an illustration, consider the following command:
205.Bd -literal -offset indent
206$ jot 6 1 10 0.5
2071
2082
2092
2102
2113
2124
213.Ed
214.Pp
215By requesting an explicit precision of 1, the values generated before rounding
216can be seen.
217The .5 values are rounded down if the integer part is even,
218up otherwise.
219.Bd -literal -offset indent
220$ jot -p 1 6 1 10 0.5
2211.0
2221.5
2232.0
2242.5
2253.0
2263.5
227.Ed
228.Pp
229By offsetting the values slightly, the values generated by the following
230command are always rounded down:
231.Bd -literal -offset indent
232$ jot -p 0 6 .9999999999 10 0.5
2331
2341
2352
2362
2373
2383
239.Ed
240.Pp
241Another way of achieving the same result is to force truncation by
242specifying an integer format:
243.Bd -literal -offset indent
244$ jot -w %d 6 1 10 0.5
245.Ed
246.Sh EXIT STATUS
247.Ex -std
248.Sh EXAMPLES
249The command
250.Dl jot - 1 10
251.Pp
252prints the integers from 1 to 10,
253while the command
254.Dl jot 21 -1 1.00
255.Pp
256prints 21 evenly spaced numbers increasing from -1 to 1.
257The
258.Tn ASCII
259character set is generated with
260.Dl jot -c 128 0
261.Pp
262and the strings xaa through xaz with
263.Dl jot -w xa%c 26 a
264.Pp
265while 20 random 8-letter strings are produced with
266.Dl "jot -r -c 160 a z | rs -g 0 8"
267.Pp
268Infinitely many
269.Em yes Ns 's
270may be obtained through
271.Dl jot -b yes 0
272.Pp
273and thirty
274.Xr ed 1
275substitution commands applying to lines 2, 7, 12, etc.\& is
276the result of
277.Dl jot -w %ds/old/new/ 30 2 - 5
278.Pp
279The stuttering sequence 9, 9, 8, 8, 7, etc.\& can be
280produced by truncating the output precision and a suitable choice of step size,
281as in
282.Dl jot -w %d - 9.5 0 -.5
283.Pp
284and a file containing exactly 1024 bytes is created with
285.Dl jot -b x 512 > block
286.Pp
287Finally, to set tabs four spaces apart starting
288from column 10 and ending in column 132, use
289.Dl expand -`jot -s, - 10 132 4`
290.Pp
291and to print all lines 80 characters or longer,
292.Dl grep `jot -s \&"\&" -b \&. 80`
293.Sh DIAGNOSTICS
294The following diagnostic messages deserve special explanation:
295.Bl -diag
296.It "illegal or unsupported format '%s'"
297The requested conversion format specifier for
298.Xr printf 3
299was not of the form
300.Dl %[#][ ][{+,-}][0-9]*[.[0-9]*]?
301where
302.Dq ?\&
303must be one of
304.Dl [l]{d,i,o,u,x}
305or
306.Dl {c,e,f,g,D,E,G,O,U,X}
307.It "range error in conversion"
308A value to be printed fell outside the range of the data type
309associated with the requested output format.
310.It "too many conversions"
311More than one conversion format specifier has been supplied,
312but only one is allowed.
313.El
314.Sh SEE ALSO
315.Xr ed 1 ,
316.Xr expand 1 ,
317.Xr rs 1 ,
318.Xr seq 1 ,
319.Xr yes 1 ,
320.Xr arc4random 3 ,
321.Xr printf 3 ,
322.Xr random 3
323.Sh HISTORY
324The
325.Nm
326utility first appeared in
327.Bx 4.2 .
328.Sh AUTHORS
329.An John A. Kunze
330