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