Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cut(1) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

grep, egrep, fgrep

paste



CUT(1,C)                    AIX Commands Reference                     CUT(1,C)



-------------------------------------------------------------------------------
cut



PURPOSE

Writes out selected fields from each line of a file.

SYNTAX


       +- -clist -----------------+   +--------+
cut ---|          +-------------+ |---|        |---|
       +- -flist -| +---------+ |-+   +- file -+
                  +-| -dchar 1|-+      ^      |
                   ^| -s      ||       +------+
                   |+---------+|
                   +-----------+


-----------------
1 The default char is a tab.


DESCRIPTION

The cut command cuts out columns from a table or fields from each line of a
file and writes these columns or fields to standard output.  If you do not
specify a file, the cut command reads standard input.

You must specify either the -c or -f flag.  The list parameter is a
comma-separated and/or minus-separated list of integer field numbers (in
increasing order).  The minus separator indicates ranges.  Some sample lists
are "1,4,7"; "1-3,8"; "-5,10" (short for "1-5,10"); and "3-" (short for third
through last field).  The fields specified by list can be a fixed number of
character 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 the cut and paste commands.

FLAGS

-clist     Specifies character positions.  For example, if you specify
           "-c1-72", the cut command writes out the first 72 characters in each
           line of the file.  There is no space between -c and list.

-dchar     Uses the specified character as the field delimiter when you specify
           the -f flag.  You must quote characters with special meaning to the
           shell, such as the space character.



Processed November 8, 1990         CUT(1,C)                                   1





CUT(1,C)                    AIX Commands Reference                     CUT(1,C)




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

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

EXAMPLE

To display several fields of each line of a file:

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

This displays the login name and full user name 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:/:/bin/sh
  daemon:*:1:1::/etc:
  bin:*:2:2::/bin:
  sys:*:3:3::/usr/src:
  adm:*:4:4:System Administrator:/usr/adm:/bin/sh
  pierre:boodwqT3irHFE:200:200:Pierre Harper:/u/pierre:/bin/sh
  joan:wijBNaYpCZuL.:202:200:Joan Brown:/u/joan:/bin/sh

then the cut command produces:

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

RELATED INFORMATION

See the following commands:  "grep, egrep, fgrep" and "paste."











Processed November 8, 1990         CUT(1,C)                                   2



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