|HP-UX Reference > C
HP-UX 11i Version 3: February 2007
cut — cut out (extract) selected fields of each line of a file
cut cuts out (extracts) columns from a table or fields from each line in a file; in data base parlance, it implements the projection of a relation. Fields as specified by list can be fixed length (defined in terms of character or byte position in a line when using the -c or -b option), or the length can vary from line to line and be marked with a field delimiter character such as the tab character (when using the -f option). cut can be used as a filter; if no files are given, the standard input is used.
When processing single-byte character sets, the -c and -b options are equivalent and produce identical results. When processing multi-byte character sets, when the -b and -n options are used together, their combined behavior is very similar, but not identical to the -c option.
Options are interpreted as follows:
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
cut supports both single- and multi-byte character code sets. International code set characters may be specified in the char given to the -d option. cut recognizes the international code set characters according to the locale specified in the LC_CTYPE environment variable.
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 " "`
Convert file source containing lines of arbitrary length into two files where file1 contains the first 500 bytes (unless the 500th byte is within a multi-byte character), and file2 contains the remainder of each line:
cut -b 1-500 -n source > file1 cut -b 500- -n source > file2
cut does not expand tabs. Pipe text through expand(1) if tab expansion is required.