xref: /netbsd/usr.bin/rs/rs.1 (revision bf9ec67e)
1.\"	$NetBSD: rs.1,v 1.6 2002/02/08 01:36:32 ross Exp $
2.\"
3.\" Copyright (c) 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"	@(#)rs.1	8.2 (Berkeley) 12/30/93
35.\"
36.Dd December 18, 2001
37.Dt RS 1
38.Os
39.Sh NAME
40.Nm rs
41.Nd reshape a data array
42.Sh SYNOPSIS
43.Nm
44.Op Fl CcSs Op Ar x
45.Op Fl GgKkw Ar N
46.Op Fl EeHhjmnTty
47.Op Ar rows Op Ar cols
48.Sh DESCRIPTION
49.Nm
50reads the standard input, interpreting each line as a row
51of blank-separated entries in an array,
52transforms the array according to the options,
53and writes it on the standard output.
54With no arguments it transforms stream input into a columnar
55format convenient for terminal viewing.
56.Pp
57The shape of the input array is deduced from the number of lines
58and the number of columns on the first line.
59If that shape is inconvenient, a more useful one might be
60obtained by skipping some of the input with the
61.Fl k
62option.
63Other options control interpretation of the input columns.
64.Pp
65The shape of the output array is influenced by the
66.Ar rows
67and
68.Ar cols
69specifications, which should be positive integers.
70If only one of them is a positive integer,
71.Nm
72computes a value for the other which will accommodate
73all of the data.
74When necessary, missing data are supplied in a manner
75specified by the options and surplus data are deleted.
76There are options to control presentation of the output columns,
77including transposition of the rows and columns.
78.Pp
79The options are described below.
80.Bl -tag -width xxxxxx -offset indent
81.It Fl C Op Ar x
82Output columns are delimited by the single character
83.Ar x .
84A missing
85.Ar x
86is taken to be
87.Sq \&^I .
88.It Fl c Op Ar x
89Input columns are delimited by the single character
90.Ar x .
91A missing
92.Ar x
93is taken to be
94.Sq \&^I .
95.It Fl e
96Consider each line of input as an array entry.
97.It Fl G Ar N
98The gutter width (inter-column space) has
99.Ar N
100percent of the maximum column width added to it.
101.It Fl g Ar N
102The gutter width (inter-column space), normally 2, is taken to be
103.Ar N .
104.It Fl H
105Like
106.Fl h ,
107but also print the length of each line.
108.It Fl h
109Print the shape of the input array and do nothing else.
110The shape is just the number of lines and the number of
111entries on the first line.
112.It Fl j
113Right adjust entries within columns.
114.It Fl K Ar N
115Like
116.Fl k ,
117but print the ignored lines.
118.It Fl k Ar N
119Ignore the first
120.Ar N
121lines of input.
122.It Fl m
123Do not trim excess delimiters from the ends of the output array.
124.It Fl n
125On lines having fewer entries than the first line,
126use null entries to pad out the line.
127Normally, missing entries are taken from the next line of input.
128.It Fl S Op Ar x
129Like
130.Fl C ,
131but padded strings of
132.Ar x
133are delimiters.
134.It Fl s Op Ar x
135Like
136.Fl c ,
137but maximal strings of
138.Ar x
139are delimiters.
140.It Fl T
141Print the pure transpose of the input, ignoring any
142.Ar rows
143or
144.Ar cols
145specification.
146.It Fl t
147Fill in the rows of the output array using the columns of the
148input array, that is, transpose the input while honoring any
149.Ar rows
150and
151.Ar cols
152specifications.
153.It Fl w Ar N
154The width of the display, normally 80, is taken to be the positive
155integer
156.Ar N .
157.It Fl y
158If there are too few entries to make up the output dimensions,
159pad the output by recycling the input from the beginning.
160Normally, the output is padded with blanks.
161.It Fl z
162Adapt column widths to fit the largest entries appearing in them.
163.El
164.Pp
165With no arguments,
166.Nm
167transposes its input, and assumes one array entry per input line
168unless the first non-ignored line is longer than the display width.
169Option letters which take numerical arguments interpret a missing
170number as zero unless otherwise indicated.
171.Sh EXAMPLES
172.Nm
173can be used as a filter to convert the stream output
174of certain programs (e.g.,
175.Ic spell ,
176.Xr du 1 ,
177.Xr file 1 ,
178.Xr look 1 ,
179.Xr nm 1 ,
180.Xr who 1 ,
181and
182.Xr wc 1 )
183into a convenient
184.Dq window
185format, as in
186.Dl who | rs
187.Pp
188This function has been incorporated into the
189.Xr ls 1
190program, though for most programs with similar output
191.Nm
192suffices.
193.Pp
194To convert stream input into vector output and back again, use
195.Dl rs 1 0 | rs 0 1
196A 10 by 10 array of random numbers from 1 to 100 and
197its transpose can be generated with
198.Dl "jot \-r 100 | rs 10 10 | tee array | rs \-T \*[Gt] tarray"
199.Pp
200In the editor
201.Xr vi 1 ,
202a file consisting of a multi-line vector with 9 elements per line
203can undergo insertions and deletions,
204and then be neatly reshaped into 9 columns with
205.Dl :1,$!rs 0 9
206.Pp
207Finally, to sort a database by the first line of each 4-line field, try
208.Dl "rs \-eC 0 4 | sort | rs \-c 0 1"
209.Sh SEE ALSO
210.Xr jot 1 ,
211.Xr pr 1 ,
212.Xr sort 1 ,
213.Xr vi 1
214.Sh BUGS
215Handles only two dimensional arrays.
216.Pp
217The algorithm currently reads the whole file into memory,
218so files that do not fit in memory will not be reshaped.
219.Pp
220Fields cannot be defined yet on character positions.
221.Pp
222Re-ordering of columns is not yet possible.
223.Pp
224There are too many options.
225