xref: /freebsd/usr.bin/rs/rs.1 (revision 5f4c09dd85bff675e0ca63c55ea3c517e0fddfcc)
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.\"	@(#)rs.1	8.2 (Berkeley) 12/30/93
29.\"
30.Dd April 7, 2015
31.Dt RS 1
32.Os
33.Sh NAME
34.Nm rs
35.Nd reshape a data array
36.Sh SYNOPSIS
37.Nm
38.Oo
39.Fl Oo Cm csCS Oc Ns Op Ar x
40.Oo Cm kKgGw Oc Ns Op Ar N
41.Cm tTeEnyjhHmz
42.Oc
43.Op Ar rows Op Ar cols
44.Sh DESCRIPTION
45The
46.Nm
47utility reads the standard input, interpreting each line as a row
48of blank-separated entries in an array,
49transforms the array according to the options,
50and writes it on the standard output.
51With no arguments it transforms stream input into a columnar
52format convenient for terminal viewing.
53.Pp
54The shape of the input array is deduced from the number of lines
55and the number of columns on the first line.
56If that shape is inconvenient, a more useful one might be
57obtained by skipping some of the input with the
58.Fl k
59option.
60Other options control interpretation of the input columns.
61.Pp
62The shape of the output array is influenced by the
63.Ar rows
64and
65.Ar cols
66specifications, which should be positive integers.
67If only one of them is a positive integer,
68.Nm
69computes a value for the other which will accommodate
70all of the data.
71When necessary, missing data are supplied in a manner
72specified by the options and surplus data are deleted.
73There are options to control presentation of the output columns,
74including transposition of the rows and columns.
75.Pp
76The following options are available:
77.Bl -tag -width indent
78.It Fl c Ns Ar x
79Input columns are delimited by the single character
80.Ar x .
81A missing
82.Ar x
83is taken to be `^I'.
84.It Fl s Ns Ar x
85Like
86.Fl c ,
87but maximal strings of
88.Ar x
89are delimiters.
90.It Fl C Ns Ar x
91Output columns are delimited by the single character
92.Ar x .
93A missing
94.Ar x
95is taken to be `^I'.
96.It Fl S Ns Ar x
97Like
98.Fl C ,
99but padded strings of
100.Ar x
101are delimiters.
102.It Fl t
103Fill in the rows of the output array using the columns of the
104input array, that is, transpose the input while honoring any
105.Ar rows
106and
107.Ar cols
108specifications.
109.It Fl T
110Print the pure transpose of the input, ignoring any
111.Ar rows
112or
113.Ar cols
114specification.
115.It Fl k Ns Ar N
116Ignore the first
117.Ar N
118lines of input.
119.It Fl K Ns Ar N
120Like
121.Fl k ,
122but print the ignored lines.
123.It Fl g Ns Ar N
124The gutter width (inter-column space), normally 2, is taken to be
125.Ar N .
126.It Fl G Ns Ar N
127The gutter width has
128.Ar N
129percent of the maximum column width added to it.
130.It Fl e
131Consider each line of input as an array entry.
132.It Fl n
133On lines having fewer entries than the first line,
134use null entries to pad out the line.
135Normally, missing entries are taken from the next line of input.
136.It Fl y
137If there are too few entries to make up the output dimensions,
138pad the output by recycling the input from the beginning.
139Normally, the output is padded with blanks.
140.It Fl h
141Print the shape of the input array and do nothing else.
142The shape is just the number of lines and the number of
143entries on the first line.
144.It Fl H
145Like
146.Fl h ,
147but also print the length of each line.
148.It Fl j
149Right adjust entries within columns.
150.It Fl w Ns Ar N
151The width of the display, normally 80, is taken to be the positive
152integer
153.Ar N .
154.It Fl m
155Do not trim excess delimiters from the ends of the output array.
156.It Fl z
157Adapt column widths to fit the largest entries appearing in them.
158.El
159.Pp
160With no arguments,
161.Nm
162transposes its input, and assumes one array entry per input line
163unless the first non-ignored line is longer than the display width.
164Option letters which take numerical arguments interpret a missing
165number as zero unless otherwise indicated.
166.Sh EXAMPLES
167The
168.Nm
169utility can be used as a filter to convert the stream output
170of certain programs (e.g.,
171.Xr spell 1 ,
172.Xr du 1 ,
173.Xr file 1 ,
174.Xr look 1 ,
175.Xr nm 1 ,
176.Xr who 1 ,
177and
178.Xr wc 1 )
179into a convenient ``window'' format, as in
180.Bd -literal -offset indent
181% who | rs
182.Ed
183.Pp
184This function has been incorporated into the
185.Xr ls 1
186program, though for most programs with similar output
187.Nm
188suffices.
189.Pp
190To convert stream input into vector output and back again, use
191.Bd -literal -offset indent
192% rs 1 0 | rs 0 1
193.Ed
194.Pp
195A 10 by 10 array of random numbers from 1 to 100 and
196its transpose can be generated with
197.Bd -literal -offset indent
198% jot \-r 100 | rs 10 10 | tee array | rs \-T > tarray
199.Ed
200.Pp
201In the editor
202.Xr vi 1 ,
203a file consisting of a multi-line vector with 9 elements per line
204can undergo insertions and deletions,
205and then be neatly reshaped into 9 columns with
206.Bd -literal -offset indent
207:1,$!rs 0 9
208.Ed
209.Pp
210Finally, to sort a database by the first line of each 4-line field, try
211.Bd -literal -offset indent
212% rs \-eC 0 4 | sort | rs \-c 0 1
213.Ed
214.Sh SEE ALSO
215.Xr jot 1 ,
216.Xr pr 1 ,
217.Xr sort 1 ,
218.Xr vi 1
219.Sh HISTORY
220The
221.Nm
222utility first appeared in
223.Bx 4.2 .
224.Sh AUTHORS
225.An John A. Kunze
226.Sh BUGS
227.Bl -item
228.It
229Handles only two dimensional arrays.
230.It
231The algorithm currently reads the whole file into memory,
232so files that do not fit in memory will not be reshaped.
233.It
234Fields cannot be defined yet on character positions.
235.It
236Re-ordering of columns is not yet possible.
237.It
238There are too many options.
239.It
240Multibyte characters are not recognized.
241.It
242Lines longer than
243.Dv LINE_MAX
244(2048) bytes are not processed and result in immediate termination of
245.Nm .
246.El
247