How To Filter Field In The File Using Cut Command | Field in the /etc/passwd File

Cut command is used to print the selected part of the Field in the file.
Example in the /etc/passwd file it has seven parameter.
Normal output Without Filtering
[root@bash ~]#cat /etc/passwd
root:x:0:0: Linux cut command is used to filter the particular specific column in the file.
root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

List of the Field /etc/passwd file
Linux /etc/passwd file it has the seven Field
adm:x:3:4:adm:/var/adm:/sbin/nologin
adm – Username
X – Password
3-UserID
4-Group ID
adm – User Identification Information
/var/adm – User Home Directory
/sbin/nologin- Command/Shell Path of the Command And Shell

FIELD IN /etc/shadow FILE
UNAME:PWD:LAST PWD CHANGE:MIN:MAX:WARN:INACTIVE:EXPIRE
1.UNAME:2.PWD:3.LAST PWD CHANGE:4.MIN:5.MAX:6.WARN:7.INACTIVE:8.EXPIRE

cat /etc/group
GROUP NAME:PWD:GROUP ID:MEMBER OF GROUP
1.Group name
2.Group Encrypted passwod
3.Group Id
4.Member of Group.


First one it has the username. Now I list out only to the user name
List The First Column
[root@bash ~]#cut -d: -f1 /etc/passwd
root
bin
daemon
adm
-d refer to the delimiter instead of tab
-f refers to the particular field
-c refers to the character list

List The Seventh Column Command or Shell Path
[root@bash ~]#cut -d: -f7 /etc/passwd
/bin/bash
/sbin/nologin
/sbin/nologin
If we need third and fourth column like userid and groupd id we can use the following command

Thrid and Fourth Field User ID Group ID.
[root@bash ~]#cut -d: -f3,4 /etc/passwd
0:0
1:1
2:2
3:4
4:7
using –c option we can filter the first selected character from the file
example /etc/shadow file we can filter only the first three character
[root@bash ~]#cut -c 1-3 /etc/shadow
roo
bin
dae
adm
lp:

Post a Comment

0 Comments