How to use the Linux cut command

PHPz
Release: 2023-05-14 21:40:04
forward
1259 people have browsed it

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]
Copy after login

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)
Copy after login

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

$ who|cut -b 3
c
c
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template