xref: /freebsd/usr.bin/jot/jot.1 (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
19b50d902SRodney W. Grimes.\" Copyright (c) 1993
29b50d902SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
39b50d902SRodney W. Grimes.\"
49b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
59b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions
69b50d902SRodney W. Grimes.\" are met:
79b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
89b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
99b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
109b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
119b50d902SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
12fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
139b50d902SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
149b50d902SRodney W. Grimes.\"    without specific prior written permission.
159b50d902SRodney W. Grimes.\"
169b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
179b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199b50d902SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
209b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269b50d902SRodney W. Grimes.\" SUCH DAMAGE.
279b50d902SRodney W. Grimes.\"
28*a811237dSMateusz Piotrowski.Dd September 21, 2019
29d078aa13SPhilippe Charnier.Dt JOT 1
30d078aa13SPhilippe Charnier.Os
31d078aa13SPhilippe Charnier.Sh NAME
32d078aa13SPhilippe Charnier.Nm jot
33d078aa13SPhilippe Charnier.Nd print sequential or random data
34d078aa13SPhilippe Charnier.Sh SYNOPSIS
358fe908efSRuslan Ermilov.Nm
36d078aa13SPhilippe Charnier.Op Fl cnr
37d078aa13SPhilippe Charnier.Op Fl b Ar word
38d078aa13SPhilippe Charnier.Op Fl w Ar word
39d078aa13SPhilippe Charnier.Op Fl s Ar string
40d078aa13SPhilippe Charnier.Op Fl p Ar precision
41ff9a78c0SRuslan Ermilov.Op Ar reps Op Ar begin Op Ar end Op Ar s
42d078aa13SPhilippe Charnier.Sh DESCRIPTION
43e8937ba0SPhilippe CharnierThe
44e8937ba0SPhilippe Charnier.Nm
45e8937ba0SPhilippe Charnierutility is used to print out increasing, decreasing, random,
469b50d902SRodney W. Grimesor redundant data, usually numbers, one per line.
47d078aa13SPhilippe Charnier.Pp
48d078aa13SPhilippe CharnierThe following options are available:
49d078aa13SPhilippe Charnier.Bl -tag -width indent
50d078aa13SPhilippe Charnier.It Fl r
5186fb9103SSteve PriceGenerate random data instead of the default sequential data.
52d078aa13SPhilippe Charnier.It Fl b Ar word
539b50d902SRodney W. GrimesJust print
54d078aa13SPhilippe Charnier.Ar word
559b50d902SRodney W. Grimesrepetitively.
56d078aa13SPhilippe Charnier.It Fl w Ar word
579b50d902SRodney W. GrimesPrint
58d078aa13SPhilippe Charnier.Ar word
599b50d902SRodney W. Grimeswith the generated data appended to it.
60d078aa13SPhilippe CharnierOctal, hexadecimal, exponential,
61d078aa13SPhilippe Charnier.Tn ASCII ,
62d078aa13SPhilippe Charnierzero padded,
639b50d902SRodney W. Grimesand right-adjusted representations
649b50d902SRodney W. Grimesare possible by using the appropriate
65d078aa13SPhilippe Charnier.Xr printf 3
669b50d902SRodney W. Grimesconversion specification inside
67d078aa13SPhilippe Charnier.Ar word ,
689b50d902SRodney W. Grimesin which case the data are inserted rather than appended.
69d078aa13SPhilippe Charnier.It Fl c
70d078aa13SPhilippe CharnierThis is an abbreviation for
71d078aa13SPhilippe Charnier.Fl w Ar %c .
72d078aa13SPhilippe Charnier.It Fl s Ar string
739b50d902SRodney W. GrimesPrint data separated by
74d078aa13SPhilippe Charnier.Ar string .
759b50d902SRodney W. GrimesNormally, newlines separate data.
76d078aa13SPhilippe Charnier.It Fl n
779b50d902SRodney W. GrimesDo not print the final newline normally appended to the output.
78d078aa13SPhilippe Charnier.It Fl p Ar precision
799b50d902SRodney W. GrimesPrint only as many digits or characters of the data
809b50d902SRodney W. Grimesas indicated by the integer
81d078aa13SPhilippe Charnier.Ar precision .
829b50d902SRodney W. GrimesIn the absence of
83d078aa13SPhilippe Charnier.Fl p ,
849b50d902SRodney W. Grimesthe precision is the greater of the precisions of
85d078aa13SPhilippe Charnier.Ar begin
869b50d902SRodney W. Grimesand
87d078aa13SPhilippe Charnier.Ar end .
889b50d902SRodney W. GrimesThe
89d078aa13SPhilippe Charnier.Fl p
909b50d902SRodney W. Grimesoption is overridden by whatever appears in a
91d078aa13SPhilippe Charnier.Xr printf 3
929b50d902SRodney W. Grimesconversion following
93d078aa13SPhilippe Charnier.Fl w .
94d078aa13SPhilippe Charnier.El
95d078aa13SPhilippe Charnier.Pp
969b50d902SRodney W. GrimesThe last four arguments indicate, respectively,
979b50d902SRodney W. Grimesthe number of data, the lower bound, the upper bound,
989b50d902SRodney W. Grimesand the step size or, for random data, the seed.
999b50d902SRodney W. GrimesWhile at least one of them must appear,
1009b50d902SRodney W. Grimesany of the other three may be omitted, and
1019b50d902SRodney W. Grimeswill be considered as such if given as
102fee14f30SDiomidis Spinellis.Fl ""
103fee14f30SDiomidis Spinellisor as an empty string.
1049b50d902SRodney W. GrimesAny three of these arguments determines the fourth.
1059b50d902SRodney W. GrimesIf four are specified and the given and computed values of
106d078aa13SPhilippe Charnier.Ar reps
1079b50d902SRodney W. Grimesconflict, the lower value is used.
108*a811237dSMateusz PiotrowskiIf one or two are specified, defaults are assigned
109*a811237dSMateusz Piotrowskistarting with
110d078aa13SPhilippe Charnier.Ar s ,
111*a811237dSMateusz Piotrowskiwhich assumes a default of 1 (or -1 if
112d078aa13SPhilippe Charnier.Ar begin
1139b50d902SRodney W. Grimesand
114d078aa13SPhilippe Charnier.Ar end
115*a811237dSMateusz Piotrowskispecify a descending range).
116*a811237dSMateusz PiotrowskiThen the default values are assigned to the leftmost omitted arguments until
117*a811237dSMateusz Piotrowskithree arguments are set.
118d078aa13SPhilippe Charnier.Pp
1199b50d902SRodney W. GrimesDefaults for the four arguments are, respectively,
1209b50d902SRodney W. Grimes100, 1, 100, and 1, except that when random data are requested,
12186fb9103SSteve Pricethe seed,
12286fb9103SSteve Price.Ar s ,
12386fb9103SSteve Priceis picked randomly.
124ff9a78c0SRuslan ErmilovThe
125ff9a78c0SRuslan Ermilov.Ar reps
126ff9a78c0SRuslan Ermilovargument is expected to be an unsigned integer,
1279b50d902SRodney W. Grimesand if given as zero is taken to be infinite.
128ff9a78c0SRuslan ErmilovThe
129ff9a78c0SRuslan Ermilov.Ar begin
1309b50d902SRodney W. Grimesand
131d078aa13SPhilippe Charnier.Ar end
132ff9a78c0SRuslan Ermilovarguments may be given as real numbers or as characters
133d078aa13SPhilippe Charnierrepresenting the corresponding value in
134d078aa13SPhilippe Charnier.Tn ASCII .
1359b50d902SRodney W. GrimesThe last argument must be a real number.
136d078aa13SPhilippe Charnier.Pp
1379b50d902SRodney W. GrimesRandom numbers are obtained through
138a26a6612SDiomidis Spinellis.Xr arc4random 3
139a26a6612SDiomidis Spinelliswhen no seed is specified,
140a26a6612SDiomidis Spinellisand through
141a26a6612SDiomidis Spinellis.Xr random 3
142a26a6612SDiomidis Spinelliswhen a seed is given.
143d129c68aSDiomidis SpinellisWhen
144d129c68aSDiomidis Spinellis.Nm
145d129c68aSDiomidis Spinellisis asked to generate random integers or characters with begin
146d129c68aSDiomidis Spinellisand end values in the range of the random number generator function
147d129c68aSDiomidis Spinellisand no format is specified with one of the
148d129c68aSDiomidis Spinellis.Fl w ,
149d129c68aSDiomidis Spinellis.Fl b ,
150d129c68aSDiomidis Spinellisor
151d129c68aSDiomidis Spinellis.Fl p
152d129c68aSDiomidis Spinellisoptions,
153d129c68aSDiomidis Spinellis.Nm
154d129c68aSDiomidis Spinelliswill arrange for all the values in the range to appear in the output
155d129c68aSDiomidis Spinelliswith an equal probability.
156d129c68aSDiomidis SpinellisIn all other cases be careful to ensure that the output format's
157d129c68aSDiomidis Spinellisrounding or truncation will not skew the distribution of output
158d129c68aSDiomidis Spinellisvalues in an unintended way.
159d129c68aSDiomidis Spinellis.Pp
1609b50d902SRodney W. GrimesThe name
161d078aa13SPhilippe Charnier.Nm
1629b50d902SRodney W. Grimesderives in part from
163d078aa13SPhilippe Charnier.Nm iota ,
1649b50d902SRodney W. Grimesa function in APL.
1659c24af3dSBrian Somers.Ss Rounding and truncation
1669c24af3dSBrian SomersThe
1679c24af3dSBrian Somers.Nm
1689c24af3dSBrian Somersutility uses double precision floating point arithmetic internally.
1699c24af3dSBrian SomersBefore printing a number, it is converted depending on the output
1709c24af3dSBrian Somersformat used.
1719c24af3dSBrian Somers.Pp
1729c24af3dSBrian SomersIf no output format is specified or the output format is a
1739c24af3dSBrian Somersfloating point format
1749c24af3dSBrian Somers.Po
1759c24af3dSBrian Somers.Sq E ,
1769c24af3dSBrian Somers.Sq G ,
1779c24af3dSBrian Somers.Sq e ,
1789c24af3dSBrian Somers.Sq f ,
1799c24af3dSBrian Somersor
1809c24af3dSBrian Somers.Sq g
1819c24af3dSBrian Somers.Pc ,
1829c24af3dSBrian Somersthe value is rounded using the
1839c24af3dSBrian Somers.Xr printf 3
1849c24af3dSBrian Somersfunction, taking into account the requested precision.
1859c24af3dSBrian Somers.Pp
1869c24af3dSBrian SomersIf the output format is an integer format
1879c24af3dSBrian Somers.Po
1889c24af3dSBrian Somers.Sq D ,
1899c24af3dSBrian Somers.Sq O ,
1909c24af3dSBrian Somers.Sq U ,
1919c24af3dSBrian Somers.Sq X ,
1929c24af3dSBrian Somers.Sq c ,
1939c24af3dSBrian Somers.Sq d ,
1949c24af3dSBrian Somers.Sq i ,
1959c24af3dSBrian Somers.Sq o ,
1969c24af3dSBrian Somers.Sq u ,
1979c24af3dSBrian Somersor
1989c24af3dSBrian Somers.Sq x
1999c24af3dSBrian Somers.Pc ,
2009c24af3dSBrian Somersthe value is converted to an integer value by truncation.
2019c24af3dSBrian Somers.Pp
2029c24af3dSBrian SomersAs an illustration, consider the following command:
2039c24af3dSBrian Somers.Bd -literal -offset indent
2049c24af3dSBrian Somers$ jot 6 1 10 0.5
2059c24af3dSBrian Somers1
2069c24af3dSBrian Somers2
2079c24af3dSBrian Somers2
2089c24af3dSBrian Somers2
2099c24af3dSBrian Somers3
2109c24af3dSBrian Somers4
2119c24af3dSBrian Somers.Ed
2129c24af3dSBrian Somers.Pp
2139c24af3dSBrian SomersBy requesting an explicit precision of 1, the values generated before rounding
2149c24af3dSBrian Somerscan be seen.
2159c24af3dSBrian SomersThe .5 values are rounded down if the integer part is even,
2169c24af3dSBrian Somersup otherwise.
2179c24af3dSBrian Somers.Bd -literal -offset indent
2189c24af3dSBrian Somers$ jot -p 1 6 1 10 0.5
2199c24af3dSBrian Somers1.0
2209c24af3dSBrian Somers1.5
2219c24af3dSBrian Somers2.0
2229c24af3dSBrian Somers2.5
2239c24af3dSBrian Somers3.0
2249c24af3dSBrian Somers3.5
2259c24af3dSBrian Somers.Ed
2269c24af3dSBrian Somers.Pp
2279c24af3dSBrian SomersBy offsetting the values slightly, the values generated by the following
2289c24af3dSBrian Somerscommand are always rounded down:
2299c24af3dSBrian Somers.Bd -literal -offset indent
2309c24af3dSBrian Somers$ jot -p 0 6 .9999999999 10 0.5
2319c24af3dSBrian Somers1
2329c24af3dSBrian Somers1
2339c24af3dSBrian Somers2
2349c24af3dSBrian Somers2
2359c24af3dSBrian Somers3
2369c24af3dSBrian Somers3
2379c24af3dSBrian Somers.Ed
2389c24af3dSBrian Somers.Pp
2399c24af3dSBrian SomersAnother way of achieving the same result is to force truncation by
2409c24af3dSBrian Somersspecifying an integer format:
2419c24af3dSBrian Somers.Bd -literal -offset indent
2429c24af3dSBrian Somers$ jot -w %d 6 1 10 0.5
2439c24af3dSBrian Somers.Ed
2446c7216dfSRuslan Ermilov.Sh EXIT STATUS
2456c7216dfSRuslan Ermilov.Ex -std
246d078aa13SPhilippe Charnier.Sh EXAMPLES
2479b50d902SRodney W. GrimesThe command
2487d71f06cSDiomidis Spinellis.Dl jot - 1 10
2497d71f06cSDiomidis Spinellis.Pp
2507d71f06cSDiomidis Spinellisprints the integers from 1 to 10,
2517d71f06cSDiomidis Spinelliswhile the command
252d078aa13SPhilippe Charnier.Dl jot 21 -1 1.00
253d078aa13SPhilippe Charnier.Pp
254d078aa13SPhilippe Charnierprints 21 evenly spaced numbers increasing from -1 to 1.
255d078aa13SPhilippe CharnierThe
256d078aa13SPhilippe Charnier.Tn ASCII
257d078aa13SPhilippe Charniercharacter set is generated with
258d078aa13SPhilippe Charnier.Dl jot -c 128 0
259d078aa13SPhilippe Charnier.Pp
2609b50d902SRodney W. Grimesand the strings xaa through xaz with
261d078aa13SPhilippe Charnier.Dl jot -w xa%c 26 a
262d078aa13SPhilippe Charnier.Pp
2639b50d902SRodney W. Grimeswhile 20 random 8-letter strings are produced with
264d078aa13SPhilippe Charnier.Dl "jot -r -c 160 a z | rs -g 0 8"
265d078aa13SPhilippe Charnier.Pp
2669b50d902SRodney W. GrimesInfinitely many
267d078aa13SPhilippe Charnier.Em yes Ns 's
2689b50d902SRodney W. Grimesmay be obtained through
269d078aa13SPhilippe Charnier.Dl jot -b yes 0
270d078aa13SPhilippe Charnier.Pp
2719b50d902SRodney W. Grimesand thirty
272d078aa13SPhilippe Charnier.Xr ed 1
2736a3e8b0aSRuslan Ermilovsubstitution commands applying to lines 2, 7, 12, etc.\& is
2749b50d902SRodney W. Grimesthe result of
275d078aa13SPhilippe Charnier.Dl jot -w %ds/old/new/ 30 2 - 5
276d078aa13SPhilippe Charnier.Pp
2776a3e8b0aSRuslan ErmilovThe stuttering sequence 9, 9, 8, 8, 7, etc.\& can be
2789c24af3dSBrian Somersproduced by truncating the output precision and a suitable choice of step size,
2799b50d902SRodney W. Grimesas in
2809c24af3dSBrian Somers.Dl jot -w %d - 9.5 0 -.5
281d078aa13SPhilippe Charnier.Pp
2829b50d902SRodney W. Grimesand a file containing exactly 1024 bytes is created with
283d078aa13SPhilippe Charnier.Dl jot -b x 512 > block
284d078aa13SPhilippe Charnier.Pp
2859b50d902SRodney W. GrimesFinally, to set tabs four spaces apart starting
2869b50d902SRodney W. Grimesfrom column 10 and ending in column 132, use
287d078aa13SPhilippe Charnier.Dl expand -`jot -s, - 10 132 4`
288d078aa13SPhilippe Charnier.Pp
2899b50d902SRodney W. Grimesand to print all lines 80 characters or longer,
290d078aa13SPhilippe Charnier.Dl grep `jot -s \&"\&" -b \&. 80`
291a866e170SRuslan Ermilov.Sh DIAGNOSTICS
2925249bd84SSheldon HearnThe following diagnostic messages deserve special explanation:
2935249bd84SSheldon Hearn.Bl -diag
2945249bd84SSheldon Hearn.It "illegal or unsupported format '%s'"
2955249bd84SSheldon HearnThe requested conversion format specifier for
2968db8a33bSSheldon Hearn.Xr printf 3
2975249bd84SSheldon Hearnwas not of the form
2988db8a33bSSheldon Hearn.Dl %[#][ ][{+,-}][0-9]*[.[0-9]*]?
2998db8a33bSSheldon Hearnwhere
3009b88faecSRuslan Ermilov.Dq ?\&
3018db8a33bSSheldon Hearnmust be one of
3028db8a33bSSheldon Hearn.Dl [l]{d,i,o,u,x}
3038db8a33bSSheldon Hearnor
3048db8a33bSSheldon Hearn.Dl {c,e,f,g,D,E,G,O,U,X}
3055249bd84SSheldon Hearn.It "range error in conversion"
3065249bd84SSheldon HearnA value to be printed fell outside the range of the data type
3075249bd84SSheldon Hearnassociated with the requested output format.
3085249bd84SSheldon Hearn.It "too many conversions"
3095249bd84SSheldon HearnMore than one conversion format specifier has been supplied,
3105249bd84SSheldon Hearnbut only one is allowed.
3115249bd84SSheldon Hearn.El
3125249bd84SSheldon Hearn.Sh SEE ALSO
3135249bd84SSheldon Hearn.Xr ed 1 ,
3145249bd84SSheldon Hearn.Xr expand 1 ,
3155249bd84SSheldon Hearn.Xr rs 1 ,
3169b3e11b8SXin LI.Xr seq 1 ,
3175249bd84SSheldon Hearn.Xr yes 1 ,
3181ab8c5beSDiomidis Spinellis.Xr arc4random 3 ,
3195249bd84SSheldon Hearn.Xr printf 3 ,
3205249bd84SSheldon Hearn.Xr random 3
32104f064d6SColin Percival.Sh HISTORY
32204f064d6SColin PercivalThe
32304f064d6SColin Percival.Nm
32404f064d6SColin Percivalutility first appeared in
32504f064d6SColin Percival.Bx 4.2 .
32621223660SAllan Jude.Sh AUTHORS
32721223660SAllan Jude.An John A. Kunze
328