linux过滤命令(Linux filter command)
Cut?
Cut isn't that "cut"? Yes! This instruction can cut a paragraph of a message to him. The message is "line"! Let's talk about it next
[root@linux cut -d'~]# separator character' -f fields
[root@linux cut -c ~]# character interval
Parameter:
-d: followed by separate characters. Used with -f;
-f: divide a message into segments according to the -d separator character, and extract the first paragraph by -f;
-c: take out the fixed character range in units of characters (characters);
Example:
Example 1: take out the PATH variable, and I'll find the third path.
[root@linux echo $PATH ~]#
/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin :/usr/games:
[root@linux echo $PATH cut -d ~]# | ':' -f 5
parameter是什么意思啊Hey #! As a result, the directory name of /usr/local/bin appears!
# because we are in: as a separator, the fifth is
/usr/local/bin!
# so if you want to list the third and fifth? That's the way it is:
[root@linux echo $PATH cut -d ~]# | ':' -f 3,5
Example two: export the output of the message to obtain twelfth characters after all strings
[root@linux export ~]#
Declare -x HISTSIZE= "1000""
Declare -x INPUTRC= "/etc/inputrc""
Declare -x KDEDIR= "/usr""
Declare -x LANG= "zh_TW.big5""
[root@linux export cut -c 12- ~]# |
HISTSIZE= "1000""
INPUTRC= "/etc/inputrc""
KDEDIR= "/usr""
LANG= "zh_TW.big5""
# know what happened? With -c, you can handle more formatted output data!
# we can also specify a range of values, such as the 12-20 cut -c 12-20 is a character, etc.!
Example three: use last to leave only the user's name in the information of this month's logged in person
[root@linux last ~]#
Vbird tty1 192.168.1.28 Mon Aug 15 11:55 - 17:48 (05:53)
Vbird tty1 192.168.1.28 Mon Aug 15 10:17 - 11:54 (01:37)
[root@linux last ~]# | cut -d '-f 1
# with last can be achieved in recent months in the host user information,
# and we can use space at intervals, remove the first information, the user account is!
But because the space between # vbird tty1 has several, is not the only one, so, if you want to find out
In fact, # tty1 not to cut -d '-f 1,2! The output will not be what we want.
Grep
Cut is just a line of messages, take out a part of what we want, and grep is a line of analysis information, if there is any information we need, will take out to the simple syntax is this:
[root@linux grep [-acinv] ~]# search string 'filename'
Parameter:
-a: search the data for the binary file in the form of text files
-c: count the number of search strings found
-i: ignore case sizes, so case names are considered the same
-n: by the way, output line numbers
-v: the reverse selection, that is, the line indicating the content of the 'search string'!
Example:
Example 1: in last, the line that appears root is taken out;
[root@linux last grep'root'~]# |
Example two: as opposed to example, remove as long as there is no root!
[root@linux last grep -v'root'~]# |
Example three: in the output message of last, take out the root and take only the first column as long as you have it
[root @ linux ~] # last | | grep 'root' cut '- f1
# 在取出 root 之后, 利用上个指令 cut 的处理, 就能够仅取得第一栏啰.
是个很棒的指令喔 grep. 他支持的语法实在是太多了~用在正规表示法里头, 能够处理的数据实在是多的很~不过, 我们这里先不谈正规表示法~下一章再来说明~您先了解一下, grep 可以解析一行文字, 取得关键词, 若该行有存在关键词, 就会整行列出来.
fate
out 是很有趣的指令, 他可以帮我们进行排序, 而且可以依据不同的数据型态来排序喔. 例如数字与文字的排序就不一样.此外, 排序的字符与语系的编码有关, 因此, 如果您需要排序时, 建议使用 lc _ all = c 来让语系统一, 数据排序比较好一些.
[root @ linux ~] # out - fbmnrtuk] [file or stdin]
参数.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论