Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cut(1) — HP-UX 8.05

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

grep(1)

paste(1)

cut(1)

NAME

cut − cut out (extract) selected fields of each line of a file

SYNOPSIS

cut −c list [file ...]
cut −f list [−d char] [−s] [file ...]

DESCRIPTION

cut cuts out (extracts) columns from a table or fields from each line of a file; in data base parlance, it implements the projection of a relation.  The fields as specified by list can be fixed length (as in character positions as on a punched card) (−c option), or the length can vary from line to line and be marked with a field delimiter character such as tab (−f option).  cut can be used as a filter; if no files are given, the standard input is used. 

Options

Options are interpreted as follows:

list A comma-separated list of integer field numbers (in increasing order), with optional − to indicate ranges as in the −o option of nroff/troff for page ranges; for example: 1,4,7; 1−3,8; −5,10 (short for 1−5,10); or 3− (short for third through last field). 

−c list Where list specifies character positions (for example, −c 1−72 passes the first 72 characters of each line). 

−f list Where list is a list of fields assumed to be separated in the file by a delimiter character (see −d); for example, −f 1,7 copies the first and seventh field only.  Lines with no field delimiters will be passed through intact (useful for table subheadings), unless −s is specified. 

−d char The character following −d is the field delimiter (−f option only).  Default is tab. Space or other characters with special meaning to the shell must be quoted. Adjacent field delimiters delimit null fields.

−s Suppresses lines with no delimiter characters in case of −f option.  Unless specified, lines with no delimiters will be passed through untouched. 

Either the −c or −f option must be specified. 

Hints

Use grep(1) to make horizontal “cuts” (by context) through a file, or paste(1) to merge files line-by-line into columns (i.e., horizontally). To reorder columns in a table, use cut and paste.

cut does not expand tabs.  Input should be piped through expand(1) if tab expansion is required.

EXTERNAL INFLUENCES

Environment Variables

LC_CTYPE determines the interpretation of text as single and/or multi-byte characters. 

If LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable.  If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG.  If any internationalization variable contains an invalid setting, cut behaves as if all internationalization variables are set to "C".  See environ(5).

International Code Set Support

The delimiter specified with the −d argument must be a single-byte character.  Otherwise, single- and multi-byte character code sets are supported. 

EXAMPLES

Password file mapping of user ID to user names:

cut −d : −f 1,5 /etc/passwd

Set environment variable name to current login name:

name=‘who am i | cut −f 1 −d " "‘

DIAGNOSTICS

line too long Line length must not exceed 1023 characters or fields. 

bad list for c/f option
Missing −c or −f option or incorrectly specified list. No error occurs if a line has fewer fields than the list calls for. 

no fields The list is empty. 

SEE ALSO

grep(1), paste(1). 

STANDARDS CONFORMANCE

cut: SVID2, XPG2, XPG3, proposed POSIX.2 FIPS (June 1990)

Hewlett-Packard Company  —  HP-UX Release 8.05: June 1991

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026