• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

cut Command Examples in Linux

by admin

The cut command extracts the specified lines of text from a file. Common cut command options and their uses are given in the following table.

Option Description
-c Specify the number of the character to cut from each line.
-d{delimiter} Separate one field from another.
-f{field numbers} Specify the field numbers to cut on as separated by the delimiter. For example, -f2 indicates the field between the first and second instances of the delimiter.
-s Suppress a line if the delimiter is not found.

Syntax

The syntax of the cut command is:

# cut [options] {file names}

The cut command is used to display only specific columns or characters from a text file or from other command outputs. For example, in the following command, we display the login names from the /etc/passwd file:

$ cut -d: -f1 /etc/passwd

cut Command Examples

1. Print a specific character/field range of each line:

# command | cut --characters|fields=1|1,10|1-10|1-|-10

2. Print a range of each line with a specific delimiter:

# command | cut --delimiter="," --characters=1

3. Print a range of each line of the specific file:

# cut --characters=1 path/to/file

4. The following command line displays the first and third fields from a colon-delimited file (extra lines stripped from output):

$ cut -d: -f1,3 /etc/passwd

5. The following command line display only the first four characters of every line in the /etc/passwd file:

$ cut -c 1-4 /etc/passwd

Filed Under: Linux

Some more articles you might also be interested in …

  1. lastb Command Examples in Linux
  2. apt-file: command not found
  3. “-bash: route: command not found” on CentOS/RHEL 8
  4. Understanding /proc/meminfo file (Analyzing Memory utilization in Linux)
  5. ac: command not found
  6. “docker dead but subsys locked” – error while starting docker
  7. tracepath Command Examples in Linux
  8. mimetype: command not found
  9. “BAD PASSWD : is too simple” – error during password change in CentOS/RHEL 7 and 8
  10. mount: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright