Skip to main content
U.S. flag

An official website of the United States government

Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

The Insider's Guide to Accessing NLM Data

cut


As new Insider's Guide classes are no longer being offered, this site is not currently being updated. Please refer to NCBI's E-utilities documentation for more up-to-date information.


The cut command trims off a portion of each line of text input to the command. To see a full list of arguments, options, and features of cut, see the cut documentation page, or type

man cut

into your terminal to see the manual page for cut.

Input

One or more lines of text.

Output

Specific portions of each of the input lines of text, as specified by the arguments.

Using cut

To use the cut command, you must specify which portion of your input you wish to retain. Only the portions of your input you specify will be output. In order to specify the portion of your input you wish to keep, you need to use either the -c or the -f argument.

The -c argument allows you to specify a range of characters which you would like to retain.

The -f argument allows you to specify a range of fields you would like to retain. By default, the tab character is the default delimiter of cut, but you can set a different delimiter using the -d argument.

With either the -c or the -f argument, you specify the range using one of four options:

  • N: Retains only the N-th character or field (counted from 1).
  • N-: Retains all characters or fields from the N-th to the end of the line.
  • N-M: Retains all characters or fields from the N-th to the M-th.
  • -M: Retains all characters or fields from the first to the M-th.

Examples

Retain only the 3rd field (fields in the input are delimited by tabs):

cut -f 3

Retain only the first four characters:

cut -c -4

Retain all but the first character:

cut -c 2-

Retain only the 2nd, 3rd and 4th fields (fields in the input are delimited by “|”):

cut -f 2-4 -d "|"

Last Reviewed: August 6, 2021