Linux cut command

Linux cut command

 Linux cut command


The Linux cut command is a text processing command. This command is used to extract the specific column from a file. You need to define the column number and column delimiter with the command.

Syntax:

cut -d<delemeter> -f<field1,field2,...> filename
  • -d This defines the deleter as a column separator. The default column separator is a single space or tab.
  • -f Specify fields (column numbers) to fetch.

Example

Grep all usernames with their home directory created on a Linux system. The /etc/passwd file contained all users on a Linux system with other details. The first file of the file contains the username and the 6’th file contain the home directory of that user.

cut -d":" -f1,6 /etc/passwd

Fetch the column numbers 1,2,3,4 and 6. Here you can define a range using hyphens like 1-4.

cut -d":" -f1-4,6 /etc/passwd

You can also define multiple ranges with a single command.

cut -d":" -f1-3,5-7 /etc/passwd
Reactions

Post a Comment

0 Comments

close