Cut
The cut command can extract text columns from a text file or text stream.
Cut syntax
[Root @ WWW ~] # Cut-D 'delimiter '-F fields <= used to have specific delimiter [root @ WWW ~] # Cut-C character range <= It is used for neatly arranged information options and parameters:-D: followed by separated characters. Used with-F;-F: Splits a piece of information into segments based on the-D separator, and uses-F to get the meaning of the segments;-C: take out a fixed character range in units of characters (characters;
The PATH variable is as follows:
[root@www ~]# echo $PATH/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/games# 1 | 2 | 3 | 4 | 5 | 6 | 7
Remove the PATH variable. I want to find the fifth path.
#echo $PATH | cut -d ':' -f 5/usr/local/bin
Remove the PATH variable. I want to find the third and fifth paths.
#echo $PATH | cut -d ':' -f 3,5/sbin:/usr/local/bin
Remove the PATH variable. I want to find the third to last path.
echo $PATH | cut -d ':' -f 3-
/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/games
Remove the PATH variable. I want to find the first to third paths.
#echo $PATH | cut -d ':' -f 1-3
/bin:/usr/bin:/sbin:
Remove the PATH variable. I want to find the first, third, and fifth paths.
echo $PATH | cut -d ':' -f 1-3,5
/bin:/usr/bin:/sbin:/usr/local/bin
Practical example: show only the/etc/passwd user and Shell
#cat /etc/passwd | cut -d ':' -f 1,7 root:/bin/bashdaemon:/bin/shbin:/bin/sh