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