/usr.bin/rs/rs.1

https://bitbucket.org/freebsd/freebsd-head/ · Unknown · 245 lines · 245 code · 0 blank · 0 comment · 0 complexity · 93e795a35ef4de5f96aed6d030f49040 MD5 · raw file

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