1RS(1) BSD General Commands Manual RS(1)
2
4 rs — reshape a data array
5
7 rs [-CcSs[x]] [-GgKkw N] [-EeHhjmnTtyz] [rows [cols]]
8
10 rs reads the standard input, interpreting each line as a row of blank-
11 separated entries in an array, transforms the array according to the op‐
12 tions, and writes it on the standard output. With no arguments
13 (argc < 2) it transforms stream input into a columnar format convenient
14 for terminal viewing, i.e. if the length (in bytes!) of the first line is
15 smaller than the display width, -et is implied, -t otherwise.
16
17 The shape of the input array is deduced from the number of lines and the
18 number of columns on the first line. If that shape is inconvenient, a
19 more useful one might be obtained by skipping some of the input with the
20 -k option. Other options control interpretation of the input columns.
21
22 The shape of the output array is influenced by the rows and cols specifi‐
23 cations, which should be positive integers. If only one of them is a
24 positive integer, rs computes a value for the other which will accommo‐
25 date all of the data. When necessary, missing data are supplied in a
26 manner specified by the options and surplus data are deleted. There are
27 options to control presentation of the output columns, including transpo‐
28 sition of the rows and columns.
29
30 The options are as follows:
31
32 -C[x] Output columns are delimited by the single character x.
33 A missing x is taken to be ‘^I’.
34
35 -c[x] Input columns are delimited by the single character x.
36 A missing x is taken to be ‘^I’.
37
38 -E Consider each character of input as an array entry.
39
40 -e Consider each line of input as an array entry.
41
42 -GN The gutter width (inter-column space) has N percent of the maximum
43 column width added to it.
44
45 -gN The gutter width, normally 2, is taken to be N.
46
47 -H Like -h, but also print the length of each line.
48
49 -h Print the shape of the input array and do nothing else. The shape
50 is just the number of lines and the number of entries on the first
51 line.
52
53 -j Right adjust entries within columns.
54
55 -KN Like -k, but print the ignored lines.
56
57 -kN Ignore the first N lines of input.
58
59 -m Do not trim excess delimiters from the ends of the output array.
60
61 -n On lines having fewer entries than the first line, use null en‐
62 tries to pad out the line. Normally, missing entries are taken
63 from the next line of input.
64
65 -S[x] Like -C, but padded strings of x are delimiters.
66
67 -s[x] Like -c, but maximal strings of x are delimiters.
68
69 -T Print the pure transpose of the input, ignoring any rows or cols
70 specification.
71
72 -t Fill in the rows of the output array using the columns of the in‐
73 put array, that is, transpose the input while honoring any rows
74 and cols specifications.
75
76 -wN The width of the display, normally 80, is taken to be the positive
77 integer N.
78
79 -y If there are too few entries to make up the output dimensions, pad
80 the output by recycling the input from the beginning. Normally,
81 the output is padded with blanks.
82
83 -z Shrink column widths to fit the largest entries appearing in them.
84
85 With no arguments, rs transposes its input, and assumes one array entry
86 per input line unless the first non-ignored line is longer than the dis‐
87 play width. Option letters which take numerical arguments interpret a
88 missing number as zero unless otherwise indicated.
89
91 LC_CTYPE The character encoding locale(1). It decides which byte se‐
92 quences form characters and what their display width is. If
93 unset or set to "C", "POSIX" or an unsupported value, each byte
94 is treated as a character of display width 1.
95
97 rs can be used as a filter to convert the stream output of certain pro‐
98 grams (e.g., spell(1), du(1), file(1), look(1), nm(1), who(1), and wc(1))
99 into a convenient “window” format, as in
100
101 $ who | rs
102
103 This function has been incorporated into the ls(1) program, though for
104 most programs with similar output rs suffices.
105
106 To convert stream input into vector output and back again, use
107
108 $ rs 1 0 | rs 0 1
109
110 A 10 by 10 array of random numbers from 1 to 100 and its transpose can be
111 generated with
112
113 $ jot -r 100 | rs 10 10 | tee array | rs -T >tarray
114
115 In the editor vi(1), a file consisting of a multi-line vector with 9 ele‐
116 ments per line can undergo insertions and deletions, and then be neatly
117 reshaped into 9 columns with
118
119 :1,$!rs 0 9
120
121 Finally, to sort a database by the first line of each 4-line field, try
122
123 $ rs -eC 0 4 | sort | rs -c 0 1
124
126 jot(1), pr(1), sort(1), vi(1)
127
129 The rs utility first appeared in 4.2BSD.
130
132 John A. Kunze
133
135 Handles only two dimensional arrays.
136
137 The algorithm currently reads the whole file into memory, so files that
138 do not fit in memory will not be reshaped.
139
140 Fields cannot be defined yet on character positions.
141
142 Re-ordering of columns is not yet possible.
143
144 There are too many options.
145
146BSD September 4, 2020 BSD