shell常用统计命令

一、wc

用来统计

主要 -l 使用

eg1: 查看rpm包个数

[root@localhost day2]# rpm -qa | wc -l

346

eg2:查看行数

[root@localhost day2]# cat ceshi 
a
b
c
d
[root@localhost day2]# wc -l < ceshi
4

二、*sort

主要用来排序

[root@localhost day2]# cat test1 
111
10
22
34
3433
998
按从小到大排序
[root@localhost day2]# sort -n test1 
10
22
34
111
998
3433
​
按从大到小排序
[root@localhost day2]# sort -rn test1 
3433
998
111
34
22
10
​
可以将/etc/passwd 中内容按照uid排序
[root@localhost day2]# sort -t : -k 3 -n /etc/passwd

三、cut

主要用来切割

可以cut --help查看帮助

[root@localhost day2]# cut -d : -f1,3,5

/etc/passwd

 

[root@localhost day2]# echo "this is a cat" | cut -c 6-10
is a 

[root@localhost day2]# cat ceshi | cut -c 6-10
is a 

[root@localhost day2]# cat ceshi 
this is a cat

b
c
d

四、 uniq

用于统计

[root@localhost day2]# cat test2 
cat 
pig
dog
bird
book
cat
pig
cat
​
按照出现频率进行排序(这里例举从高到低频率)
[root@localhost day2]# sort test2 | uniq -c | sort  -rn
      2 pig
      2 cat
      1 dog
      1 cat 
      1 book
      1 bird
#sort test2是将test2中单词按照字母顺序排序,接着管道传到uniq -c是给出不同单词出现的频率,最后sort -rn 是将sort test2 | uniq -c的内容按照频率排出。

按照被访问频率从高到底排序,只输出ip

 [root@localhost httpd]# cut -d " " -f1  /var/log/httpd/access_log | sort | uniq -c | sort -rn
      9 192.168.157.131
      3 192.168.157.136
其中cut -d " " -f1 /var/log/httpd/access_log是将如图内容中的ip分割出来,接着传给sort将ip按照大小排序,然后再传给uniq -c是给出访问频率,最后sort -rn 将频率从高到低排出

五、tr

可以替换或者删除

[root@localhost day2]# echo "hello SHell" | tr "A-Z" "a-z"
hello shell

[root@localhost ~]# echo "my name is xiaoming" | tr "m" "n"
ny nane is xiaoning

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值