1 .\"
   2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
   3 .\" permission to reproduce portions of its copyrighted documentation.
   4 .\" Original documentation from The Open Group can be obtained online at
   5 .\" http://www.opengroup.org/bookstore/.
   6 .\"
   7 .\" The Institute of Electrical and Electronics Engineers and The Open
   8 .\" Group, have given us permission to reprint portions of their
   9 .\" documentation.
  10 .\"
  11 .\" In the following statement, the phrase ``this text'' refers to portions
  12 .\" of the system documentation.
  13 .\"
  14 .\" Portions of this text are reprinted and reproduced in electronic form
  15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
  16 .\" Standard for Information Technology -- Portable Operating System
  17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
  18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
  19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
  20 .\" between these versions and the original IEEE and The Open Group
  21 .\" Standard, the original IEEE and The Open Group Standard is the referee
  22 .\" document.  The original Standard can be obtained online at
  23 .\" http://www.opengroup.org/unix/online.html.
  24 .\"
  25 .\" This notice shall appear on any product containing this material.
  26 .\"
  27 .\" The contents of this file are subject to the terms of the
  28 .\" Common Development and Distribution License (the "License").
  29 .\" You may not use this file except in compliance with the License.
  30 .\"
  31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  32 .\" or http://www.opensolaris.org/os/licensing.
  33 .\" See the License for the specific language governing permissions
  34 .\" and limitations under the License.
  35 .\"
  36 .\" When distributing Covered Code, include this CDDL HEADER in each
  37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  38 .\" If applicable, add the following below this CDDL HEADER, with the
  39 .\" fields enclosed by brackets "[]" replaced with your own identifying
  40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
  41 .\"
  42 .\"
  43 .\" Copyright 1989 AT&T
  44 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
  45 .\" Copyright (c) 1999, Sun Microsystems, Inc.  All Rights Reserved
  46 .\"
  47 .TH CUT 1 "Apr 29, 1999"
  48 .SH NAME
  49 cut \- cut out selected fields of each line of a file
  50 .SH SYNOPSIS
  51 .LP
  52 .nf
  53 \fBcut\fR \fB-b\fR \fIlist\fR [\fB-n\fR] [\fIfile\fR]...
  54 .fi
  55 
  56 .LP
  57 .nf
  58 \fBcut\fR \fB-c\fR \fIlist\fR [\fIfile\fR]...
  59 .fi
  60 
  61 .LP
  62 .nf
  63 \fBcut\fR \fB-f\fR \fIlist\fR [\fB-d\fR \fIdelim\fR] [\fB-s\fR] [\fIfile\fR]...
  64 .fi
  65 
  66 .SH DESCRIPTION
  67 .sp
  68 .LP
  69 Use the \fBcut\fR utility to cut out columns from a table or fields from each
  70 line of a file; in data base parlance, it implements the projection of a
  71 relation. The fields as specified by \fIlist\fR can be fixed length, that is,
  72 character positions as on a punched card (\fB-c\fR option) or the length can
  73 vary from line to line and be marked with a field delimiter character like TAB
  74 (\fB-f\fR option). \fBcut\fR can be used as a filter.
  75 .sp
  76 .LP
  77 Either the \fB-b\fR, \fB-c\fR, or \fB-f\fR option must be specified.
  78 .sp
  79 .LP
  80 Use \fBgrep\fR(1) to make horizontal ``cuts'' (by context) through a file, or
  81 \fBpaste\fR(1) to put files together column-wise (that is, horizontally). To
  82 reorder columns in a table, use \fBcut\fR and \fBpaste\fR.
  83 .SH OPTIONS
  84 .sp
  85 .LP
  86 The following options are supported:
  87 .sp
  88 .ne 2
  89 .na
  90 \fB\fIlist\fR \fR
  91 .ad
  92 .RS 13n
  93 A comma-separated or blank-character-separated list of integer field numbers
  94 (in increasing order), with optional \fB\(mi\fR to indicate ranges (for
  95 instance, \fB1,4,7\fR; \fB1\(mi3,8\fR; \fB\(mi5,10\fR (short for
  96 \fB1\(mi5,10\fR); or \fB3\(mi\fR (short for third through last field)).
  97 .RE
  98 
  99 .sp
 100 .ne 2
 101 .na
 102 \fB\fB\fR\fB-b\fR \fIlist\fR \fR
 103 .ad
 104 .RS 13n
 105 The \fIlist\fR following \fB-b\fR specifies byte positions (for instance,
 106 \fB-b1\fR\fB-72\fR would pass the first 72 bytes of each line). When \fB-b\fR
 107 and \fB-n\fR are used together, \fIlist\fR is adjusted so that no multi-byte
 108 character is split.
 109 .RE
 110 
 111 .sp
 112 .ne 2
 113 .na
 114 \fB\fB\fR\fB-c\fR \fIlist\fR \fR
 115 .ad
 116 .RS 13n
 117 The \fIlist\fR following \fB-c\fR specifies character positions (for instance,
 118 \fB-c1\fR\fB-72\fR would pass the first 72 characters of each line).
 119 .RE
 120 
 121 .sp
 122 .ne 2
 123 .na
 124 \fB\fB\fR\fB-d\fR \fIdelim\fR \fR
 125 .ad
 126 .RS 13n
 127 The character following \fB-d\fR is the field delimiter (\fB-f\fR option only).
 128 Default is \fItab\fR. Space or other characters with special meaning to the
 129 shell must be quoted. \fIdelim\fR can be a multi-byte character.
 130 .RE
 131 
 132 .sp
 133 .ne 2
 134 .na
 135 \fB\fB\fR\fB-f\fR \fIlist\fR \fR
 136 .ad
 137 .RS 13n
 138 The \fIlist\fR following \fB-f\fR is a list of fields assumed to be separated
 139 in the file by a delimiter character (see \fB-d\fR ); for instance,
 140 \fB-f1\fR\fB,7\fR copies the first and seventh field only. Lines with no field
 141 delimiters will be passed through intact (useful for table subheadings), unless
 142 \fB-s\fR is specified.
 143 .RE
 144 
 145 .sp
 146 .ne 2
 147 .na
 148 \fB\fB-n\fR \fR
 149 .ad
 150 .RS 13n
 151 Do not split characters. When \fB-b\fR \fIlist\fR and \fB-n\fR are used
 152 together, \fIlist\fR is adjusted so that no multi-byte character is split.
 153 .RE
 154 
 155 .sp
 156 .ne 2
 157 .na
 158 \fB\fB-s\fR \fR
 159 .ad
 160 .RS 13n
 161 Suppresses lines with no delimiter characters in case of \fB-f\fR option.
 162 Unless specified, lines with no delimiters will be passed through untouched.
 163 .RE
 164 
 165 .SH OPERANDS
 166 .sp
 167 .LP
 168 The following operands are supported:
 169 .sp
 170 .ne 2
 171 .na
 172 \fB\fIfile\fR \fR
 173 .ad
 174 .RS 9n
 175 A path name of an input file. If no \fIfile\fR operands are specified, or if a
 176 \fIfile\fR operand is \fB\(mi\fR, the standard input will be used.
 177 .RE
 178 
 179 .SH USAGE
 180 .sp
 181 .LP
 182 See \fBlargefile\fR(5) for the description of the behavior of \fBcut\fR when
 183 encountering files greater than or equal to 2 Gbyte (2^31 bytes).
 184 .SH EXAMPLES
 185 .LP
 186 \fBExample 1 \fRMapping user IDs
 187 .sp
 188 .LP
 189 A mapping of user \fBIDs\fR to names follows:
 190 
 191 .sp
 192 .in +2
 193 .nf
 194 example% \fBcut -d: -f1,5 /etc/passwd\fR
 195 .fi
 196 .in -2
 197 .sp
 198 
 199 .LP
 200 \fBExample 2 \fRSetting current login name
 201 .sp
 202 .LP
 203 To set \fBname\fR to current login name:
 204 
 205 .sp
 206 .in +2
 207 .nf
 208 example$ \fBname=\(gawho am i | cut -f1 -d' '\(ga\fR
 209 .fi
 210 .in -2
 211 .sp
 212 
 213 .SH ENVIRONMENT VARIABLES
 214 .sp
 215 .LP
 216 See \fBenviron\fR(5) for descriptions of the following environment variables
 217 that affect the execution of \fBcut\fR: \fBLANG\fR, \fBLC_ALL\fR,
 218 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
 219 .SH EXIT STATUS
 220 .sp
 221 .LP
 222 The following exit values are returned:
 223 .sp
 224 .ne 2
 225 .na
 226 \fB\fB0\fR \fR
 227 .ad
 228 .RS 7n
 229 All input files were output successfully.
 230 .RE
 231 
 232 .sp
 233 .ne 2
 234 .na
 235 \fB\fB>0\fR \fR
 236 .ad
 237 .RS 7n
 238 An error occurred.
 239 .RE
 240 
 241 .SH ATTRIBUTES
 242 .sp
 243 .LP
 244 See \fBattributes\fR(5) for descriptions of the following attributes:
 245 .sp
 246 
 247 .sp
 248 .TS
 249 box;
 250 c | c
 251 l | l .
 252 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 253 _
 254 CSI     Enabled
 255 _
 256 Interface Stability     Standard
 257 .TE
 258 
 259 .SH SEE ALSO
 260 .sp
 261 .LP
 262 \fBgrep\fR(1), \fBpaste\fR(1), \fBattributes\fR(5), \fBenviron\fR(5),
 263 \fBlargefile\fR(5), \fBstandards\fR(5)
 264 .SH DIAGNOSTICS
 265 .sp
 266 .ne 2
 267 .na
 268 \fB\fBcut: \fR\fB-n\fR\fB may only be used with \fR\fB-b\fR \fR
 269 .ad
 270 .sp .6
 271 .RS 4n
 272 
 273 .RE
 274 
 275 .sp
 276 .ne 2
 277 .na
 278 \fB\fBcut: \fR\fB-d\fR\fB may only be used with \fR\fB-f\fR \fR
 279 .ad
 280 .sp .6
 281 .RS 4n
 282 
 283 .RE
 284 
 285 .sp
 286 .ne 2
 287 .na
 288 \fB\fBcut: \fR\fB-s\fR\fB may only be used with \fR\fB-f\fR \fR
 289 .ad
 290 .sp .6
 291 .RS 4n
 292 
 293 .RE
 294 
 295 .sp
 296 .ne 2
 297 .na
 298 \fB\fBcut: cannot open \fR\fI<file>\fR \fR
 299 .ad
 300 .sp .6
 301 .RS 4n
 302 Either \fIfile\fR cannot be read or does not exist.  If multiple files are
 303 present, processing continues.
 304 .RE
 305 
 306 .sp
 307 .ne 2
 308 .na
 309 \fB\fBcut: no delimiter specified\fR \fR
 310 .ad
 311 .sp .6
 312 .RS 4n
 313 Missing \fIdelim\fR on \fB-d\fR option.
 314 .RE
 315 
 316 .sp
 317 .ne 2
 318 .na
 319 \fB\fBcut: invalid delimiter\fR \fR
 320 .ad
 321 .sp .6
 322 .RS 4n
 323 
 324 .RE
 325 
 326 .sp
 327 .ne 2
 328 .na
 329 \fB\fBcut: no \fIlist\fR\fR\fB specified\fR \fR
 330 .ad
 331 .sp .6
 332 .RS 4n
 333 Missing \fIlist\fR on \fB-b\fR, \fB-c\fR, or \fB-f\fR option.
 334 .RE
 335 
 336 .sp
 337 .ne 2
 338 .na
 339 \fB\fBcut: invalid range specifier\fR \fR
 340 .ad
 341 .sp .6
 342 .RS 4n
 343 
 344 .RE
 345 
 346 .sp
 347 .ne 2
 348 .na
 349 \fB\fBcut: too many ranges specified\fR \fR
 350 .ad
 351 .sp .6
 352 .RS 4n
 353 
 354 .RE
 355 
 356 .sp
 357 .ne 2
 358 .na
 359 \fB\fBcut: range must be increasing\fR \fR
 360 .ad
 361 .sp .6
 362 .RS 4n
 363 
 364 .RE
 365 
 366 .sp
 367 .ne 2
 368 .na
 369 \fB\fBcut: invalid character in range\fR \fR
 370 .ad
 371 .sp .6
 372 .RS 4n
 373 
 374 .RE
 375 
 376 .sp
 377 .ne 2
 378 .na
 379 \fB\fBcut: internal error processing input\fR \fR
 380 .ad
 381 .sp .6
 382 .RS 4n
 383 
 384 .RE
 385 
 386 .sp
 387 .ne 2
 388 .na
 389 \fB\fBcut: invalid multibyte character\fR \fR
 390 .ad
 391 .sp .6
 392 .RS 4n
 393 
 394 .RE
 395 
 396 .sp
 397 .ne 2
 398 .na
 399 \fB\fBcut: unable to allocate enough memory\fR \fR
 400 .ad
 401 .sp .6
 402 .RS 4n
 403 
 404 .RE
 405