RS(1)
NAME
rs − reshape a data array
SYNOPSIS
rs [ −[csCS][x][kKgGw][N]tTeEnyjhHm ] [ rows [ cols ] ]
DESCRIPTION
Rs reads the standard input, interpreting each line as a row of blank-separated entries in an array, transforms the array according to the options, and writes it on the standard output. With no arguments it transforms stream input into a columnar format convenient for terminal viewing.
Given positive integers for rows and cols, the program produces output with the corresponding shape, truncating surplus data and supplying missing data as necessary. If only one of them is a positive integer, then rs computes a value for the other which will accomodate all of the data.
The options are described below.
−cxInput columns are delimited by the single character x. A missing x is taken to be ‘^I’.
−sxLike −c, but maximal strings of x are delimiters.
−CxOutput columns are delimited by the single character x. A missing x is taken to be ‘^I’.
−SxLike −C, but maximal strings of x are delimiters.
−tFill in the rows of the output array using the columns of the input array, that is, transpose the input while honoring any rows and cols specifications.
−TPrint the pure transpose of the input, ignoring any rows or cols specification.
−kNIgnore the first N lines of input.
−KNLike −k, but print the ignored lines.
−gNThe gutter width (inter-column space), normally 2, is taken to be N.
−GNThe gutter width has N percent of the maximum column width added to it.
−eConsider each line of input as an array entry.
−nOn lines having fewer entries than the first line, use null entries to pad out the line. Normally, missing entries are taken from the next line of input.
−yIf there are too few entries to make up the output dimensions, pad the output by recycling the input from the beginning. Normally, the output is padded with blanks.
−hPrint the shape of the input array and do nothing else. The shape is just the number of lines and the number of entries on the first line.
−HLike −h, but also print the length of each line.
−jRight adjust entries within columns.
−wNThe width of the display, normally 80, is taken to be the positive integer N.
−mDo not trim excess delimiters from the ends of the output array.
With no arguments, rs behaves as if given −et. Option letters which take numerical arguments interpret a missing number as zero unless otherwise indicated.
EXAMPLES
Rs can be used as a filter to convert the stream output of several programs (e.g., spell, du, file, look, nm, who, and wc(1)) into a convenient “window” format, as in
who | rs
This function has been incorporated into the ls(1) program, though for most programs with similar output rs suffices.
To convert stream input into vector output and back again, use
rs 1 0 | rs 0 1
A 10 by 10 array of random numbers from 1 to 100 and its transpose can be generated with
jot −r 100 | rs 10 10 | tee array | rs −T > tarray
In the editor ex(1), a file consisting of a 3-column table that has undergone insertions and deletions can be neatly reshaped into 3 columns with
:1,$!rs 0 3
Finally, to sort a database by the first line of each 4-line field, try
rs −lC 0 4 | sort | rs −c 0 1
SEE ALSO
jot(1), ex(1), sort(1), pr(1),
AUTHOR
John Kunze
BUGS
Handles only two dimensional arrays.
Fields cannot be defined yet on character positions.
Re-ordering of columns is not yet possible.
There are too many options.