1994-05-27 12:33:43 +00:00
|
|
|
.\" Copyright (c) 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)rs.1 8.2 (Berkeley) 12/30/93
|
1999-08-28 01:08:13 +00:00
|
|
|
.\" $FreeBSD$
|
1994-05-27 12:33:43 +00:00
|
|
|
.\"
|
1997-08-07 06:42:37 +00:00
|
|
|
.Dd December 30, 1993
|
|
|
|
.Dt RS 1
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm rs
|
|
|
|
.Nd reshape a data array
|
|
|
|
.Sh SYNOPSIS
|
2000-11-20 19:21:22 +00:00
|
|
|
.Nm
|
1997-08-07 06:42:37 +00:00
|
|
|
.Oo
|
2000-12-27 16:52:31 +00:00
|
|
|
.Fl Oo Cm csCS Oc Ns Op Ar x
|
|
|
|
.Oo Cm kKgGw Oc Ns Op Ar N
|
|
|
|
.Cm tTeEnyjhHmz
|
1997-08-07 06:42:37 +00:00
|
|
|
.Oc
|
|
|
|
.Op Ar rows Op Ar cols
|
|
|
|
.Sh DESCRIPTION
|
2002-04-20 12:18:28 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility reads the standard input, interpreting each line as a row
|
1994-05-27 12:33:43 +00:00
|
|
|
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.
|
1997-08-07 06:42:37 +00:00
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
The shape of the input array is deduced from the number of lines
|
|
|
|
and the number of columns on the first line.
|
|
|
|
If that shape is inconvenient, a more useful one might be
|
1997-08-07 06:42:37 +00:00
|
|
|
obtained by skipping some of the input with the
|
|
|
|
.Fl k
|
|
|
|
option.
|
1994-05-27 12:33:43 +00:00
|
|
|
Other options control interpretation of the input columns.
|
1997-08-07 06:42:37 +00:00
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
The shape of the output array is influenced by the
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ar rows
|
1994-05-27 12:33:43 +00:00
|
|
|
and
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ar cols
|
1994-05-27 12:33:43 +00:00
|
|
|
specifications, which should be positive integers.
|
|
|
|
If only one of them is a positive integer,
|
1997-08-07 06:42:37 +00:00
|
|
|
.Nm
|
1994-05-27 12:33:43 +00:00
|
|
|
computes a value for the other which will accommodate
|
|
|
|
all of the data.
|
|
|
|
When necessary, missing data are supplied in a manner
|
|
|
|
specified by the options and surplus data are deleted.
|
|
|
|
There are options to control presentation of the output columns,
|
|
|
|
including transposition of the rows and columns.
|
1997-08-07 06:42:37 +00:00
|
|
|
.Pp
|
|
|
|
The following options are available:
|
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Fl c Ns Ar x
|
|
|
|
Input columns are delimited by the single character
|
|
|
|
.Ar x .
|
|
|
|
A missing
|
|
|
|
.Ar x
|
|
|
|
is taken to be `^I'.
|
|
|
|
.It Fl s Ns Ar x
|
|
|
|
Like
|
|
|
|
.Fl c ,
|
|
|
|
but maximal strings of
|
|
|
|
.Ar x
|
|
|
|
are delimiters.
|
|
|
|
.It Fl C Ns Ar x
|
|
|
|
Output columns are delimited by the single character
|
|
|
|
.Ar x .
|
|
|
|
A missing
|
|
|
|
.Ar x
|
|
|
|
is taken to be `^I'.
|
|
|
|
.It Fl S Ns Ar x
|
|
|
|
Like
|
|
|
|
.Fl C ,
|
|
|
|
but padded strings of
|
|
|
|
.Ar x
|
|
|
|
are delimiters.
|
|
|
|
.It Fl t
|
1994-05-27 12:33:43 +00:00
|
|
|
Fill in the rows of the output array using the columns of the
|
|
|
|
input array, that is, transpose the input while honoring any
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ar rows
|
1994-05-27 12:33:43 +00:00
|
|
|
and
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ar cols
|
1994-05-27 12:33:43 +00:00
|
|
|
specifications.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl T
|
1994-05-27 12:33:43 +00:00
|
|
|
Print the pure transpose of the input, ignoring any
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ar rows
|
1994-05-27 12:33:43 +00:00
|
|
|
or
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ar cols
|
1994-05-27 12:33:43 +00:00
|
|
|
specification.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl k Ns Ar N
|
|
|
|
Ignore the first
|
|
|
|
.Ar N
|
|
|
|
lines of input.
|
|
|
|
.It Fl K Ns Ar N
|
|
|
|
Like
|
|
|
|
.Fl k ,
|
|
|
|
but print the ignored lines.
|
|
|
|
.It Fl g Ns Ar N
|
|
|
|
The gutter width (inter-column space), normally 2, is taken to be
|
|
|
|
.Ar N .
|
|
|
|
.It Fl G Ns Ar N
|
|
|
|
The gutter width has
|
|
|
|
.Ar N
|
|
|
|
percent of the maximum column width added to it.
|
|
|
|
.It Fl e
|
1994-05-27 12:33:43 +00:00
|
|
|
Consider each line of input as an array entry.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl n
|
1994-05-27 12:33:43 +00:00
|
|
|
On 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.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl y
|
1994-05-27 12:33:43 +00:00
|
|
|
If 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.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl h
|
1994-05-27 12:33:43 +00:00
|
|
|
Print 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.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl H
|
|
|
|
Like
|
|
|
|
.Fl h ,
|
|
|
|
but also print the length of each line.
|
|
|
|
.It Fl j
|
1994-05-27 12:33:43 +00:00
|
|
|
Right adjust entries within columns.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl w Ns Ar N
|
1994-05-27 12:33:43 +00:00
|
|
|
The width of the display, normally 80, is taken to be the positive
|
1997-08-07 06:42:37 +00:00
|
|
|
integer
|
|
|
|
.Ar N .
|
|
|
|
.It Fl m
|
1994-05-27 12:33:43 +00:00
|
|
|
Do not trim excess delimiters from the ends of the output array.
|
1997-08-07 06:42:37 +00:00
|
|
|
.It Fl z
|
|
|
|
Adapt column widths to fit the largest entries appearing in them.
|
|
|
|
.El
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
With no arguments,
|
1997-08-07 06:42:37 +00:00
|
|
|
.Nm
|
1994-05-27 12:33:43 +00:00
|
|
|
transposes its input, and assumes one array entry per input line
|
|
|
|
unless the first non-ignored line is longer than the display width.
|
|
|
|
Option letters which take numerical arguments interpret a missing
|
|
|
|
number as zero unless otherwise indicated.
|
1997-08-07 06:42:37 +00:00
|
|
|
.Sh EXAMPLES
|
2002-04-20 12:18:28 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility can be used as a filter to convert the stream output
|
1994-05-27 12:33:43 +00:00
|
|
|
of certain programs (e.g.,
|
1997-08-07 06:42:37 +00:00
|
|
|
.Xr spell ,
|
|
|
|
.Xr du ,
|
|
|
|
.Xr file ,
|
|
|
|
.Xr look ,
|
|
|
|
.Xr nm ,
|
|
|
|
.Xr who ,
|
1994-05-27 12:33:43 +00:00
|
|
|
and
|
1997-08-07 06:42:37 +00:00
|
|
|
.Xr wc 1 )
|
1994-05-27 12:33:43 +00:00
|
|
|
into a convenient ``window'' format, as in
|
1997-08-07 06:42:37 +00:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
% who | rs
|
|
|
|
.Ed
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
This function has been incorporated into the
|
1997-08-07 06:42:37 +00:00
|
|
|
.Xr ls 1
|
1994-05-27 12:33:43 +00:00
|
|
|
program, though for most programs with similar output
|
1997-08-07 06:42:37 +00:00
|
|
|
.Nm
|
1994-05-27 12:33:43 +00:00
|
|
|
suffices.
|
1997-08-07 06:42:37 +00:00
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
To convert stream input into vector output and back again, use
|
1997-08-07 06:42:37 +00:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
% rs 1 0 | rs 0 1
|
|
|
|
.Ed
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
A 10 by 10 array of random numbers from 1 to 100 and
|
|
|
|
its transpose can be generated with
|
1997-08-07 06:42:37 +00:00
|
|
|
.Bd -literal -offset indent
|
2001-07-15 08:06:20 +00:00
|
|
|
% jot \-r 100 | rs 10 10 | tee array | rs \-T > tarray
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
In the editor
|
1997-08-07 06:42:37 +00:00
|
|
|
.Xr vi 1 ,
|
1994-05-27 12:33:43 +00:00
|
|
|
a file consisting of a multi-line vector with 9 elements per line
|
|
|
|
can undergo insertions and deletions,
|
|
|
|
and then be neatly reshaped into 9 columns with
|
1997-08-07 06:42:37 +00:00
|
|
|
.Bd -literal -offset indent
|
1994-05-27 12:33:43 +00:00
|
|
|
:1,$!rs 0 9
|
1997-08-07 06:42:37 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
Finally, to sort a database by the first line of each 4-line field, try
|
1997-08-07 06:42:37 +00:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
% rs \-eC 0 4 | sort | rs \-c 0 1
|
|
|
|
.Ed
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr jot 1 ,
|
|
|
|
.Xr pr 1 ,
|
|
|
|
.Xr sort 1 ,
|
|
|
|
.Xr vi 1
|
|
|
|
.Sh BUGS
|
2000-12-19 16:00:12 +00:00
|
|
|
.Bl -item
|
|
|
|
.It
|
1994-05-27 12:33:43 +00:00
|
|
|
Handles only two dimensional arrays.
|
2000-12-19 16:00:12 +00:00
|
|
|
.It
|
1994-05-27 12:33:43 +00:00
|
|
|
The algorithm currently reads the whole file into memory,
|
|
|
|
so files that do not fit in memory will not be reshaped.
|
2000-12-19 16:00:12 +00:00
|
|
|
.It
|
1994-05-27 12:33:43 +00:00
|
|
|
Fields cannot be defined yet on character positions.
|
2000-12-19 16:00:12 +00:00
|
|
|
.It
|
1994-05-27 12:33:43 +00:00
|
|
|
Re-ordering of columns is not yet possible.
|
2000-12-19 16:00:12 +00:00
|
|
|
.It
|
1994-05-27 12:33:43 +00:00
|
|
|
There are too many options.
|
2000-12-19 16:00:12 +00:00
|
|
|
.El
|