《鸟哥的Linux私房菜》之管道命令的使用
时间:2018-12-17 16:29 来源:linux.it.net.cn 作者:IT
1、cut
-d 按照其后面的字符串分割
-f 分割后取哪一个位置的分割项
-c 按照字符分割后取哪一个位置到哪一个位置
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/soft/jdk1.8.0_144/bin:/root/soft/hadoop-2.7.2/bin:/root/soft/hadoop-2.7.2/sbin:/root/bin
echo $PATH | cut -d ':' -f2
/usr/local/bin
按照:分割后取第二项(shell的下标从1开始)
echo $PATH | cut -c 5-
/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/soft/jdk1.8.0_144/bin:/root/soft/hadoop-2.7.2/bin:/root/soft/hadoop-2.7.2/sbin:/root/bin
按照字符分割后取第5位及其后面的字符
echo $PATH | cut -c 5-10
/local
按照字符分割后取5,6,7,8,9,10位
2、grep
grep [-acinv] '' filename
-c 计算出待搜寻字符串出现的次数
-i 忽略大小写
-n 顺便输出行号
-v 反向选择
[root@localhost ~]# cat 1.txt
aaaaaaaaaaa
AAAAAA
bbbb
bbb
ccccccc
ddddddddd
eeeeeeeeee
ffffffffffff
ggggggggg
GGGGGGGG
[root@localhost ~]# grep -c 'a' 1.txt
[root@localhost ~]# grep -ic 'a' 1.txt
3、sort
sort [-fbMnrtuk] [file or stdin]
[root@localhost ~]# cat 1.txt | sort -t ':' -k 2
ffffffffffff:1
AAAAAA:10000
bbbb:2
GGGGGGGG:22
bbb:33
ccccccc:4
ggggggggg:4
vvvv:7
eeeeeeeeee:9
ddddddddd:90
xxxx:98
aaaaaaaaaaa:99
[root@localhost ~]# cat 1.txt | sort -t ':' -k 2 -c
[root@localhost ~]#
[root@localhost ~]# cat 1.txt | sort -t ':' -k 2 -n
ffffffffffff:1
bbbb:2
ccccccc:4
ggggggggg:4
vvvv:7
eeeeeeeeee:9
GGGGGGGG:22
bbb:33
ddddddddd:90
xxxx:98
aaaaaaaaaaa:99
AAAAAA:10000
(责任编辑:IT)
1、cut -d 按照其后面的字符串分割 -f 分割后取哪一个位置的分割项 -c 按照字符分割后取哪一个位置到哪一个位置 echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/soft/jdk1.8.0_144/bin:/root/soft/hadoop-2.7.2/bin:/root/soft/hadoop-2.7.2/sbin:/root/bin echo $PATH | cut -d ':' -f2 /usr/local/bin 按照:分割后取第二项(shell的下标从1开始) echo $PATH | cut -c 5- /local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/soft/jdk1.8.0_144/bin:/root/soft/hadoop-2.7.2/bin:/root/soft/hadoop-2.7.2/sbin:/root/bin 按照字符分割后取第5位及其后面的字符 echo $PATH | cut -c 5-10 /local 按照字符分割后取5,6,7,8,9,10位 2、grep grep [-acinv] '' filename -c 计算出待搜寻字符串出现的次数 -i 忽略大小写 -n 顺便输出行号 -v 反向选择 [root@localhost ~]# cat 1.txt aaaaaaaaaaa AAAAAA bbbb bbb ccccccc ddddddddd eeeeeeeeee ffffffffffff ggggggggg GGGGGGGG [root@localhost ~]# grep -c 'a' 1.txt [root@localhost ~]# grep -ic 'a' 1.txt 3、sort sort [-fbMnrtuk] [file or stdin] [root@localhost ~]# cat 1.txt | sort -t ':' -k 2 ffffffffffff:1 AAAAAA:10000 bbbb:2 GGGGGGGG:22 bbb:33 ccccccc:4 ggggggggg:4 vvvv:7 eeeeeeeeee:9 ddddddddd:90 xxxx:98 aaaaaaaaaaa:99 [root@localhost ~]# cat 1.txt | sort -t ':' -k 2 -c [root@localhost ~]# [root@localhost ~]# cat 1.txt | sort -t ':' -k 2 -n ffffffffffff:1 bbbb:2 ccccccc:4 ggggggggg:4 vvvv:7 eeeeeeeeee:9 GGGGGGGG:22 bbb:33 ddddddddd:90 xxxx:98 aaaaaaaaaaa:99 AAAAAA:10000 (责任编辑:IT) |