2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
28 .\" @(#)rs.1 8.2 (Berkeley) 12/30/93
29 .\" $FreeBSD: src/usr.bin/rs/rs.1,v 1.4.2.5 2002/06/21 15:28:55 charnier Exp $
30 .\" $DragonFly: src/usr.bin/rs/rs.1,v 1.3 2006/04/17 18:01:37 swildner Exp $
37 .Nd reshape a data array
41 .Fl Oo Cm csCS Oc Ns Op Ar x
42 .Oo Cm kKgGw Oc Ns Op Ar N
45 .Op Ar rows Op Ar cols
49 utility reads the standard input, interpreting each line as a row
50 of blank-separated entries in an array,
51 transforms the array according to the options,
52 and writes it on the standard output.
53 With no arguments it transforms stream input into a columnar
54 format convenient for terminal viewing.
56 The shape of the input array is deduced from the number of lines
57 and the number of columns on the first line.
58 If that shape is inconvenient, a more useful one might be
59 obtained by skipping some of the input with the
62 Other options control interpretation of the input columns.
64 The shape of the output array is influenced by the
68 specifications, which should be positive integers.
69 If only one of them is a positive integer,
71 computes a value for the other which will accommodate
73 When necessary, missing data are supplied in a manner
74 specified by the options and surplus data are deleted.
75 There are options to control presentation of the output columns,
76 including transposition of the rows and columns.
78 The following options are available:
79 .Bl -tag -width indent
81 Input columns are delimited by the single character
89 but maximal strings of
93 Output columns are delimited by the single character
101 but padded strings of
105 Fill in the rows of the output array using the columns of the
106 input array, that is, transpose the input while honoring any
112 Print the pure transpose of the input, ignoring any
124 but print the ignored lines.
126 The gutter width (inter-column space), normally 2, is taken to be
131 percent of the maximum column width added to it.
133 Consider each line of input as an array entry.
135 On lines having fewer entries than the first line,
136 use null entries to pad out the line.
137 Normally, missing entries are taken from the next line of input.
139 If there are too few entries to make up the output dimensions,
140 pad the output by recycling the input from the beginning.
141 Normally, the output is padded with blanks.
143 Print the shape of the input array and do nothing else.
144 The shape is just the number of lines and the number of
145 entries on the first line.
149 but also print the length of each line.
151 Right adjust entries within columns.
153 The width of the display, normally 80, is taken to be the positive
157 Do not trim excess delimiters from the ends of the output array.
159 Adapt column widths to fit the largest entries appearing in them.
164 transposes its input, and assumes one array entry per input line
165 unless the first non-ignored line is longer than the display width.
166 Option letters which take numerical arguments interpret a missing
167 number as zero unless otherwise indicated.
171 utility can be used as a filter to convert the stream output
172 of certain programs (e.g.,
181 into a convenient ``window'' format, as in
182 .Bd -literal -offset indent
186 This function has been incorporated into the
188 program, though for most programs with similar output
192 To convert stream input into vector output and back again, use
193 .Bd -literal -offset indent
197 A 10 by 10 array of random numbers from 1 to 100 and
198 its transpose can be generated with
199 .Bd -literal -offset indent
200 % jot \-r 100 | rs 10 10 | tee array | rs \-T > tarray
205 a file consisting of a multi-line vector with 9 elements per line
206 can undergo insertions and deletions,
207 and then be neatly reshaped into 9 columns with
208 .Bd -literal -offset indent
212 Finally, to sort a database by the first line of each 4-line field, try
213 .Bd -literal -offset indent
214 % rs \-eC 0 4 | sort | rs \-c 0 1
224 Handles only two dimensional arrays.
226 The algorithm currently reads the whole file into memory,
227 so files that do not fit in memory will not be reshaped.
229 Fields cannot be defined yet on character positions.
231 Re-ordering of columns is not yet possible.
233 There are too many options.