In this article you will learn how to use cut command on linux system. In computing, cut is a Linux/Unix command line function which is generally used to pull out sections from each line of input.
Cut command path.
root@linuxpcfix [~]#which cut
/bin/cut
cut command options
-b select only bytes from line
-c select characters from line
-f select field
-d use character DELIMITER instead of a tab for the field delimiter.
-s, –only-delimited do not print lines not containing delimiters.
#cut [option] file name
this is my first page
is this my first page
page is first
If you want to cut from third character to end of the line then use the following command.
is is my first page
this my first page
ge is first
To select the fourth field of each line execute the following command
first
first
To select the third field
my
my
first
this is my first command hellow world colour ram bob name karen
asshish charles movie picture SATA TRP linux pc fix dot com
unix support dot co in india pak test page
To select from third field to end of the line.
my first command hellow world colour ram bob name karen
movie picture SATA TRP linux pc fix dot com
dott coo inn india pak test page
Select the field from 3 to 9 use the below command.
my first command hellow world colour
movie picture SATA TRP linux
dott coo inn india pak
Select the field 1 and 3 use the below command.
this my
asshish
unix
If field are separated by space then use the following command.
first
father
mother
son
If field are separated by : then use the following command
user:x:502:502:user:/home/user:/bin/bash
user1:x:503:503:user1:/home/user1:/bin/bash
user2:x:504:504:user2:/home/user2:/bin/bash
user3:x:505:505:user3:/home/user3:/bin/bash
user4:x:506:506:user4:/home/user4:/bin/bash
To select first field execute the below command
user1
user2
user3
user4
To select sixth field execute the below command
/user
/home/user1
/home/user2
/home/user3
/home/user4
To select first and seventh field execute the below command
user:/bin/bash
user1:/bin/bash
user2:/bin/bash
user3:/bin/bash
user4:/bin/bash
Mathew,Father,40,Manager
Diana,Mother,35,Housewife
John,Son,10,student
To get the name, relationship and age, excluding the profession as below
Mathew,Father,40
Diana,Mother,35
John,Son,10
