Linux cut command - output selected bytes, characters or fields from each line of the file

Linux cut command: output selected bytes, characters or fields from each line of the file

Linux cut command Function Description

Use the cut command to output selected bytes, characters, or fields (fields) from each line of a file.

Only one of the -b, -c or -f options can be used.

Each list is made specifically for a category, or different categories can be separated by commas to be displayed simultaneously.

The input order will be used as the read order, and each can be entered only once.

Linux cut command Syntax

cut [option] [ file ]

The meaning of each option in the command is shown in the table:

Option Description
-b <List> Select only those bytes specified
-c <List> Select only those characters specified
-d <List> Use specified delimiters instead of tabs as region delimiters
-f <List> Specify the list of fields in the file that are envisaged to be delimited (by default, tabs)
-n Unseparate multi-byte characters. Use only with the -b option. If the last byte of a character falls within the range indicated by the -b option’s list argument, the character will be written out; otherwise the character will be excluded
-s Do not print lines that do not contain a delimiter

When using the -b, -c, and -f options, each parameter format represents the following ranges:

  • N: The Nth byte, character or field counting from the first.
  • N-: All characters, bytes or fields from the beginning of the Nth to the end of the line in which it is located.
  • N-M: All characters, bytes or fields from the Nth up to and including the Mth.
  • -M: All characters, bytes or fields from the first one up to and including the Mth one.

Linux cut command Demo

cut outputs selected bytes

Linux cut command

cut outputs the selected character

Linux cut command

Display the user login name and username full name fields in the file /etc/passwd, which are the first and fifth fields, separated by a colon

[root@rhel ~]# cut -f 1,5-d: /etc/passwd
root:root
bin:bin
daemon:daemon
adm:adm
lp:lp
sync:sync
shutdown:shutdown
halt:halt
mail:mail
uucp:uucp
operator:operator
games:games
gopher:gopher
ftp:FTP User
nobody:Nobody
dbus:System message bus
usbmuxd:usbmuxd user
vcsa:virtual console memory owner
rpc:Rpcbind Daemon
rtkit:RealtimeKit
avahi-autoipd:Avahi IPv4LL Stack
abrt:
rpcuser:RPC Service User
nfsnobody:Anonymous NFS User
haldaemon:HAL daemon
gdm:
ntp:
apache:Apache
saslauth: ''Saslauthd user''
postfix:
pulse:PulseAudio System Daemon
sshd:Privilege-separated SSH
tcpdump:
Like(1)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?