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