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