How to use the Linux cut command

PHPz
PHPzforward
2023-05-14 21:40:041363browse

Linux cut command is used to display the text from num1 to num2 from the beginning of each line.

Syntax:

cut  [-bn] [file]
cut [-c] [file]
cut [-df] [file]

Instructions:

cut command cuts bytes, characters and fields and writes these bytes, characters, and fields to standard output.

If the File parameter is not specified, the cut command will read the standard input. One of the -b, -c, or -f flags must be specified.

Parameters:

  • -b: Split in bytes. These byte positions ignore multibyte character boundaries unless the -n flag is also specified.

  • -c: Split in character units.

  • -d: Custom delimiter, default is tab character.

  • -f: Used with -d to specify which area to display.

  • -n: Unsplit multi-byte characters. Only used with the -b flag. If the last byte of a character falls within the
    range indicated by the List parameter of the -b flag, the character will be written; otherwise, the character will be excluded

Example

When you execute the who command, something similar to the following will be output:

$ who
rocrocket :0           2009-01-08 11:07
rocrocket pts/0        2009-01-08 11:23 (:0.0)
rocrocket pts/1        2009-01-08 14:15 (:0.0)

If we want to extract the 3rd byte of each line, this is it:

$ who|cut -b 3
c
c

The above is the detailed content of How to use the Linux cut command. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete