19b50d902SRodney W. Grimes.\" Copyright (c) 1993 29b50d902SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 39b50d902SRodney W. Grimes.\" 49b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 59b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions 69b50d902SRodney W. Grimes.\" are met: 79b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 89b50d902SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 99b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 109b50d902SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 119b50d902SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 12*fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 139b50d902SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 149b50d902SRodney W. Grimes.\" without specific prior written permission. 159b50d902SRodney W. Grimes.\" 169b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 179b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 189b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 199b50d902SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 209b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 219b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 229b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 239b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 249b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 259b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 269b50d902SRodney W. Grimes.\" SUCH DAMAGE. 279b50d902SRodney W. Grimes.\" 2821223660SAllan Jude.Dd April 7, 2015 29e25f6756SPhilippe Charnier.Dt RS 1 30e25f6756SPhilippe Charnier.Os 31e25f6756SPhilippe Charnier.Sh NAME 32e25f6756SPhilippe Charnier.Nm rs 33e25f6756SPhilippe Charnier.Nd reshape a data array 34e25f6756SPhilippe Charnier.Sh SYNOPSIS 358fe908efSRuslan Ermilov.Nm 36e25f6756SPhilippe Charnier.Oo 37f4ddfb38SRuslan Ermilov.Fl Oo Cm csCS Oc Ns Op Ar x 38f4ddfb38SRuslan Ermilov.Oo Cm kKgGw Oc Ns Op Ar N 39f4ddfb38SRuslan Ermilov.Cm tTeEnyjhHmz 40e25f6756SPhilippe Charnier.Oc 41e25f6756SPhilippe Charnier.Op Ar rows Op Ar cols 42e25f6756SPhilippe Charnier.Sh DESCRIPTION 43e8937ba0SPhilippe CharnierThe 44e8937ba0SPhilippe Charnier.Nm 45e8937ba0SPhilippe Charnierutility reads the standard input, interpreting each line as a row 469b50d902SRodney W. Grimesof blank-separated entries in an array, 479b50d902SRodney W. Grimestransforms the array according to the options, 489b50d902SRodney W. Grimesand writes it on the standard output. 499b50d902SRodney W. GrimesWith no arguments it transforms stream input into a columnar 509b50d902SRodney W. Grimesformat convenient for terminal viewing. 51e25f6756SPhilippe Charnier.Pp 529b50d902SRodney W. GrimesThe shape of the input array is deduced from the number of lines 539b50d902SRodney W. Grimesand the number of columns on the first line. 549b50d902SRodney W. GrimesIf that shape is inconvenient, a more useful one might be 55e25f6756SPhilippe Charnierobtained by skipping some of the input with the 56e25f6756SPhilippe Charnier.Fl k 57e25f6756SPhilippe Charnieroption. 589b50d902SRodney W. GrimesOther options control interpretation of the input columns. 59e25f6756SPhilippe Charnier.Pp 609b50d902SRodney W. GrimesThe shape of the output array is influenced by the 61e25f6756SPhilippe Charnier.Ar rows 629b50d902SRodney W. Grimesand 63e25f6756SPhilippe Charnier.Ar cols 649b50d902SRodney W. Grimesspecifications, which should be positive integers. 659b50d902SRodney W. GrimesIf only one of them is a positive integer, 66e25f6756SPhilippe Charnier.Nm 679b50d902SRodney W. Grimescomputes a value for the other which will accommodate 689b50d902SRodney W. Grimesall of the data. 699b50d902SRodney W. GrimesWhen necessary, missing data are supplied in a manner 709b50d902SRodney W. Grimesspecified by the options and surplus data are deleted. 719b50d902SRodney W. GrimesThere are options to control presentation of the output columns, 729b50d902SRodney W. Grimesincluding transposition of the rows and columns. 73e25f6756SPhilippe Charnier.Pp 74e25f6756SPhilippe CharnierThe following options are available: 75e25f6756SPhilippe Charnier.Bl -tag -width indent 76e25f6756SPhilippe Charnier.It Fl c Ns Ar x 77e25f6756SPhilippe CharnierInput columns are delimited by the single character 78e25f6756SPhilippe Charnier.Ar x . 79e25f6756SPhilippe CharnierA missing 80e25f6756SPhilippe Charnier.Ar x 81e25f6756SPhilippe Charnieris taken to be `^I'. 82e25f6756SPhilippe Charnier.It Fl s Ns Ar x 83e25f6756SPhilippe CharnierLike 84e25f6756SPhilippe Charnier.Fl c , 85e25f6756SPhilippe Charnierbut maximal strings of 86e25f6756SPhilippe Charnier.Ar x 87e25f6756SPhilippe Charnierare delimiters. 88e25f6756SPhilippe Charnier.It Fl C Ns Ar x 89e25f6756SPhilippe CharnierOutput columns are delimited by the single character 90e25f6756SPhilippe Charnier.Ar x . 91e25f6756SPhilippe CharnierA missing 92e25f6756SPhilippe Charnier.Ar x 93e25f6756SPhilippe Charnieris taken to be `^I'. 94e25f6756SPhilippe Charnier.It Fl S Ns Ar x 95e25f6756SPhilippe CharnierLike 96e25f6756SPhilippe Charnier.Fl C , 97e25f6756SPhilippe Charnierbut padded strings of 98e25f6756SPhilippe Charnier.Ar x 99e25f6756SPhilippe Charnierare delimiters. 100e25f6756SPhilippe Charnier.It Fl t 1019b50d902SRodney W. GrimesFill in the rows of the output array using the columns of the 1029b50d902SRodney W. Grimesinput array, that is, transpose the input while honoring any 103e25f6756SPhilippe Charnier.Ar rows 1049b50d902SRodney W. Grimesand 105e25f6756SPhilippe Charnier.Ar cols 1069b50d902SRodney W. Grimesspecifications. 107e25f6756SPhilippe Charnier.It Fl T 1089b50d902SRodney W. GrimesPrint the pure transpose of the input, ignoring any 109e25f6756SPhilippe Charnier.Ar rows 1109b50d902SRodney W. Grimesor 111e25f6756SPhilippe Charnier.Ar cols 1129b50d902SRodney W. Grimesspecification. 113e25f6756SPhilippe Charnier.It Fl k Ns Ar N 114e25f6756SPhilippe CharnierIgnore the first 115e25f6756SPhilippe Charnier.Ar N 116e25f6756SPhilippe Charnierlines of input. 117e25f6756SPhilippe Charnier.It Fl K Ns Ar N 118e25f6756SPhilippe CharnierLike 119e25f6756SPhilippe Charnier.Fl k , 120e25f6756SPhilippe Charnierbut print the ignored lines. 121e25f6756SPhilippe Charnier.It Fl g Ns Ar N 122e25f6756SPhilippe CharnierThe gutter width (inter-column space), normally 2, is taken to be 123e25f6756SPhilippe Charnier.Ar N . 124e25f6756SPhilippe Charnier.It Fl G Ns Ar N 125e25f6756SPhilippe CharnierThe gutter width has 126e25f6756SPhilippe Charnier.Ar N 127e25f6756SPhilippe Charnierpercent of the maximum column width added to it. 128e25f6756SPhilippe Charnier.It Fl e 1299b50d902SRodney W. GrimesConsider each line of input as an array entry. 130e25f6756SPhilippe Charnier.It Fl n 1319b50d902SRodney W. GrimesOn lines having fewer entries than the first line, 1329b50d902SRodney W. Grimesuse null entries to pad out the line. 1339b50d902SRodney W. GrimesNormally, missing entries are taken from the next line of input. 134e25f6756SPhilippe Charnier.It Fl y 1359b50d902SRodney W. GrimesIf there are too few entries to make up the output dimensions, 1369b50d902SRodney W. Grimespad the output by recycling the input from the beginning. 1379b50d902SRodney W. GrimesNormally, the output is padded with blanks. 138e25f6756SPhilippe Charnier.It Fl h 1399b50d902SRodney W. GrimesPrint the shape of the input array and do nothing else. 1409b50d902SRodney W. GrimesThe shape is just the number of lines and the number of 1419b50d902SRodney W. Grimesentries on the first line. 142e25f6756SPhilippe Charnier.It Fl H 143e25f6756SPhilippe CharnierLike 144e25f6756SPhilippe Charnier.Fl h , 145e25f6756SPhilippe Charnierbut also print the length of each line. 146e25f6756SPhilippe Charnier.It Fl j 1479b50d902SRodney W. GrimesRight adjust entries within columns. 148e25f6756SPhilippe Charnier.It Fl w Ns Ar N 1499b50d902SRodney W. GrimesThe width of the display, normally 80, is taken to be the positive 150e25f6756SPhilippe Charnierinteger 151e25f6756SPhilippe Charnier.Ar N . 152e25f6756SPhilippe Charnier.It Fl m 1539b50d902SRodney W. GrimesDo not trim excess delimiters from the ends of the output array. 154e25f6756SPhilippe Charnier.It Fl z 155e25f6756SPhilippe CharnierAdapt column widths to fit the largest entries appearing in them. 156e25f6756SPhilippe Charnier.El 157e25f6756SPhilippe Charnier.Pp 1589b50d902SRodney W. GrimesWith no arguments, 159e25f6756SPhilippe Charnier.Nm 1609b50d902SRodney W. Grimestransposes its input, and assumes one array entry per input line 1619b50d902SRodney W. Grimesunless the first non-ignored line is longer than the display width. 1629b50d902SRodney W. GrimesOption letters which take numerical arguments interpret a missing 1639b50d902SRodney W. Grimesnumber as zero unless otherwise indicated. 164e25f6756SPhilippe Charnier.Sh EXAMPLES 165e8937ba0SPhilippe CharnierThe 166e8937ba0SPhilippe Charnier.Nm 167e8937ba0SPhilippe Charnierutility can be used as a filter to convert the stream output 1689b50d902SRodney W. Grimesof certain programs (e.g., 1696a1be1f5SPhilippe Charnier.Xr spell 1 , 1706a1be1f5SPhilippe Charnier.Xr du 1 , 1716a1be1f5SPhilippe Charnier.Xr file 1 , 1726a1be1f5SPhilippe Charnier.Xr look 1 , 1736a1be1f5SPhilippe Charnier.Xr nm 1 , 1746a1be1f5SPhilippe Charnier.Xr who 1 , 1759b50d902SRodney W. Grimesand 176e25f6756SPhilippe Charnier.Xr wc 1 ) 1779b50d902SRodney W. Grimesinto a convenient ``window'' format, as in 178e25f6756SPhilippe Charnier.Bd -literal -offset indent 179e25f6756SPhilippe Charnier% who | rs 180e25f6756SPhilippe Charnier.Ed 181e25f6756SPhilippe Charnier.Pp 1829b50d902SRodney W. GrimesThis function has been incorporated into the 183e25f6756SPhilippe Charnier.Xr ls 1 1849b50d902SRodney W. Grimesprogram, though for most programs with similar output 185e25f6756SPhilippe Charnier.Nm 1869b50d902SRodney W. Grimessuffices. 187e25f6756SPhilippe Charnier.Pp 1889b50d902SRodney W. GrimesTo convert stream input into vector output and back again, use 189e25f6756SPhilippe Charnier.Bd -literal -offset indent 190e25f6756SPhilippe Charnier% rs 1 0 | rs 0 1 191e25f6756SPhilippe Charnier.Ed 192e25f6756SPhilippe Charnier.Pp 1939b50d902SRodney W. GrimesA 10 by 10 array of random numbers from 1 to 100 and 1949b50d902SRodney W. Grimesits transpose can be generated with 195e25f6756SPhilippe Charnier.Bd -literal -offset indent 196e25f6756SPhilippe Charnier% jot \-r 100 | rs 10 10 | tee array | rs \-T > tarray 197e25f6756SPhilippe Charnier.Ed 198e25f6756SPhilippe Charnier.Pp 1999b50d902SRodney W. GrimesIn the editor 200e25f6756SPhilippe Charnier.Xr vi 1 , 2019b50d902SRodney W. Grimesa file consisting of a multi-line vector with 9 elements per line 2029b50d902SRodney W. Grimescan undergo insertions and deletions, 2039b50d902SRodney W. Grimesand then be neatly reshaped into 9 columns with 204e25f6756SPhilippe Charnier.Bd -literal -offset indent 2059b50d902SRodney W. Grimes:1,$!rs 0 9 206e25f6756SPhilippe Charnier.Ed 207e25f6756SPhilippe Charnier.Pp 2089b50d902SRodney W. GrimesFinally, to sort a database by the first line of each 4-line field, try 209e25f6756SPhilippe Charnier.Bd -literal -offset indent 210e25f6756SPhilippe Charnier% rs \-eC 0 4 | sort | rs \-c 0 1 211e25f6756SPhilippe Charnier.Ed 212e25f6756SPhilippe Charnier.Sh SEE ALSO 213e25f6756SPhilippe Charnier.Xr jot 1 , 214e25f6756SPhilippe Charnier.Xr pr 1 , 215e25f6756SPhilippe Charnier.Xr sort 1 , 216e25f6756SPhilippe Charnier.Xr vi 1 21704f064d6SColin Percival.Sh HISTORY 21804f064d6SColin PercivalThe 21904f064d6SColin Percival.Nm 22004f064d6SColin Percivalutility first appeared in 22104f064d6SColin Percival.Bx 4.2 . 22221223660SAllan Jude.Sh AUTHORS 22321223660SAllan Jude.An John A. Kunze 224e25f6756SPhilippe Charnier.Sh BUGS 2259b88faecSRuslan Ermilov.Bl -item 2269b88faecSRuslan Ermilov.It 2279b50d902SRodney W. GrimesHandles only two dimensional arrays. 2289b88faecSRuslan Ermilov.It 2299b50d902SRodney W. GrimesThe algorithm currently reads the whole file into memory, 2309b50d902SRodney W. Grimesso files that do not fit in memory will not be reshaped. 2319b88faecSRuslan Ermilov.It 2329b50d902SRodney W. GrimesFields cannot be defined yet on character positions. 2339b88faecSRuslan Ermilov.It 2349b50d902SRodney W. GrimesRe-ordering of columns is not yet possible. 2359b88faecSRuslan Ermilov.It 2369b50d902SRodney W. GrimesThere are too many options. 237752448ceSTim J. Robbins.It 238752448ceSTim J. RobbinsMultibyte characters are not recognized. 239c23211e9SJaakko Heinonen.It 240c23211e9SJaakko HeinonenLines longer than 241c23211e9SJaakko Heinonen.Dv LINE_MAX 242c23211e9SJaakko Heinonen(2048) bytes are not processed and result in immediate termination of 243c23211e9SJaakko Heinonen.Nm . 2449b88faecSRuslan Ermilov.El 245