What is a FETCH command? to put it bluntly, a piece of data is analyzed to take out what we want. or by analyzing the keywords, get the line we want! However, it is important to note that, in general, the retrieval of information is usually for "one line" to analyze , not the entire information analysis of the ~ below we introduce two very common information retrieval commands of the Cut command:
Cut is not "cut"? That's right! This command can be a piece of information to him "cut" out ~ processing of information is in "line" units! Let's talk about it at the bottom:
[Email protected] ~]#Cut-D'Delimited characters'-F Fields <==used to have specific delimiter characters [[email protected]~]#Cut-C character Interval <==information options and parameters for neat arrangement:-D: followed by delimited characters. andF used together;-F: Divides a piece of information into segments based on the delimiter character of-D, using-F take out the meaning of paragraph;-C: Remove the fixed character interval in units of character (characters); example one: Take the path variable out and I'll find the fifth path. [[Email protected]~]#Echo$PATH/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/x11r6/bin:/usr/games:#1|2|3|4|5|6|7[[Email protected]~]#Echo$PATH |Cut-D':'-F5# as shown in the figures above, we are separated by ":" and therefore appear/usr/local/Bin # So if you want to list the first3and section5it? , that's it: [[email protected]~]#Echo$PATH |Cut-D':'-F3,5Example Two: The export output of the information to obtain the first Acharacter after all string [[email protected]~]# Exportdeclare-X histsize=" +"Declare-X inputrc="/ETC/INPUTRC"Declare-X kdedir="/ usr"Declare-X lang="Zh_tw.big5"..... (other omitted) ... note that each data is a neatly arranged output! If we don't want to "declare-x ", # You have to do this: [[email protected]~]# Export |Cut-C A-histsize=" +"INPUTRC="/ETC/INPUTRC"Kdedir="/ usr"LANG="Zh_tw.big5"..... (Other omitted) ... # You know what's going on? With-C can handle the output data with the format of the comparison! # We can also specify a range of values, such as A- -The character, isCut-C A- -Wait a minute! Example three: With Lastwill display the information of the lander, leaving only the user name [[email protected]~]# LastRoot pts/1 192.168.201.101Sat Feb7 A: *Still loggedinchRoot pts/1 192.168.201.101Fri Feb6 A: -- -: $( .: -) root pts/1 192.168.201.254Thu Feb5 A:Panax Notoginseng- at: -( on: -)# LastCan output "account/terminal/source/Date Time "data, and is arranged neatly [[email protected]~]# Last|Cut-D' '-F1# By the result of the output we can find that the first blank delimited field represents the account, so use the command as above: # but because root pts/1There are several spaces between, and not just one, so if you want to find the # pts/1In fact, can notCut-D' '-F1,2Oh! The result of the output will not be what we want.
The main purpose of cut is to decompose the data in the same row! "Most commonly used when analyzing some data or text data!" This is because sometimes we use some characters as split parameters, and then we cut the data to get the data we need. Especially when parsing the log file! However, cut can be a bit more laborious when dealing with data that is connected to multiple spaces.
Reference:http://vbird.dic.ksu.edu.tw/linux_basic/0320bash.php#pipe