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