Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cut(1) — OSF/1 X2.0-8 MIPS

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

grep(1)

/egrep(1)

/fgrep(1)

join(1)

paste(1)

cut(1)  —  Commands

OSF

NAME

cut − Displays selected characters or fields from each line of a file

SYNOPSIS

cut -clist [ file ... ]

cut -flist [-dcharacter] [-s] [ file ... ]

The cut command locates the specified fields in each line of the specified file and writes the characters in them to standard output. 

FLAGS

-clistSpecifies byte positions.  For example, if you specify -c1-72, cut writes out the first 72 bytes in each line of the file.  Note that there is no space between -c and list. 

-dcharacter
Uses the specified character as the field delimiter (separator) when you specify the -f flag.  You must quote characters with special meaning to the shell, such as the space character.  Any character can be used as character. 

-flistSpecifies a list of fields assumed to be separated in the file by a field delimiter character, specified by the -d flag or the tab character by default.  For example, if you specify -f1,7, cut writes out only the first and seventh fields of each line.  If a line contains no field delimiters, cut passes them through intact (useful for table subheadings), unless you specify the -s flag. 

-sSuppresses lines that do not contain delimiter characters (use only with the -f flag). 

DESCRIPTION

If you do not specify a file, cut reads standard input. 

You must specify either the -c flag (to select bytes) or the -f flag (to select fields).  The list argument is a list of integer field or character numbers (in ascending order) that are separated by commas, dashes, or both.  The dash separator indicates ranges. 

Some sample list specifications are as follows:

1,4,7First, fourth, and seventh bytes or fields. 

1-3,8First through third and eighth bytes or fields. 

-5,10First through fifth and tenth bytes or fields. 

3-Third through last bytes or fields. 

The fields specified by list can be a fixed number of byte positions, or the length can vary from line to line and be marked with a field delimiter character, such as a tab character. 

You can also use the grep command to make horizontal cuts through a file and the paste command to put the files back together.  To change the order of columns in a file, use cut and paste. 

Japanese Language Support

The character argument can be any single-byte or multi-byte character. 

EXAMPLES

To display several fields of each line of a file, enter:

cut -f1,5 -d: /etc/passwd

This displays the login name and full username fields of the system password file.  These are the first and fifth fields (-f1,5) separated by colons (-d:). 

So, if the /etc/passwd file looks like this:

su:UHuj9Pgdvz0J":0:0:User with special privileges:/:
daemon:∗:1:1::/etc:
bin:∗:2:2::/bin:
sys:∗:3:3::/usr/src:
adm:∗:4:4:System Administrator:/usr/adm:
pierre:∗:200:200:Pierre Harper:/u/pierre:
joan:∗:202:200:Joan Brown:/u/joan:

Then, cut -f1,5 -d: /etc/passwd produces this output:

su:User with special privileges
daemon:
bin:
sys:
adm:System Administrator
pierre:Pierre Harper
joan:Joan Brown

RELATED INFORMATION

Commands:  grep(1)/egrep(1)/fgrep(1), join(1), paste(1). 

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