写点什么

软件测试学习笔记丨 Linux 命令 uniq 去重

作者:测试人
  • 2024-01-29
    北京
  • 本文字数:1338 字

    阅读完需:约 4 分钟

素材(统计 IP 出现次数)

[ck289433@shell.ceshiren.com test]$ cat uniq_demo.txt ck141906 pts/0 120.52.147.49ck140081 pts/13 113.65.231.23ck140081 pts/12 113.65.231.23ck140081 pts/4 221.219.101.18282894931 pts/12 36.112.85.17918221511 pts/10 223.71.133.4218221511 pts/2 223.71.133.4268821400 pts/4 183.63.81.21118221511 pts/5 223.71.133.4204300137 pts/0 223.104.212.185root pts/10 223.71.133.4218221511 pts/5 223.71.133.4218221511 pts/4 223.71.133.4216210504 pts/3 58.33.96.123xly20456 pts/2 120.52.147.46ck146119 pts/2 116.237.250.188ck143117 pts/11 60.208.90.202ck146119 pts/11 116.237.250.188ck146119 pts/10 116.237.250.18870146364 pts/2 106.39.114.13413863896 pts/9 183.6.105.176root pts/5 223.71.133.4218221511 pts/3 223.71.133.4218221511 pts/9 223.71.133.42ck153117 pts/5 60.208.90.20250153372 pts/4 223.104.148.19ck153117 pts/3 60.208.90.20218221511 pts/9 223.71.133.42root pts/5 223.71.133.42root pts/4 223.71.133.4218221511 pts/3 223.71.133.42ck146400 pts/2 112.10.50.241ck148853 pts/5 219.137.140.14995015293 pts/9 36.113.11.39ck141731 pts/14 61.140.133.9621609891 pts/12 101.230.255.20295015293 pts/11 36.113.11.3921609891 pts/10 58.35.66.24321609891 pts/9 101.230.255.20221609891 pts/4 101.230.255.202ck148853 pts/3 119.131.106.4421609891 pts/5 101.230.255.202ck141731 pts/2 61.140.133.9621609891 pts/4 58.35.66.24321609891 pts/3 58.35.66.243ck141731 pts/2 61.140.133.9668949047 pts/13 183.228.90.226ck144530 pts/10 116.233.212.19ck153117 pts/3 60.208.90.202ck146264 pts/0 111.23.244.189ck153307 pts/12 119.253.43.100ck143117 pts/12 221.219.101.182root pts/3 223.71.133.4250153372 pts/11 117.136.68.46ck153307 pts/10 119.253.43.100ck144530 pts/4 116.233.212.1970146364 pts/10 106.39.114.13470146364 pts/4 106.39.114.13426611853 pts/2 111.197.21.14112221712 pts/0 101.228.81.7318760789 pts/0 1.95.141.31ck140752 pts/2 111.202.144.35ck140752 pts/10 111.202.144.35ck155454 pts/1 117.149.23.19481368355 pts/5 220.249.55.194ck151573 pts/9 124.74.76.12604300137 pts/5 180.168.96.17468949047 pts/3 183.228.90.22608036051 pts/2 182.138.102.27ck146400 pts/1 112.10.50.241dx371407 pts/0 111.196.166.76
复制代码

1. 跳过前 N 项-f,对第 N+1 项去重

注意:只有挨在一起的内容会进行去重

uniq -f 2 uniq_demo.txt
复制代码




2. 先排序,再去重,最后加统计-c

cat uniq_demo.txt | sort -k 3 | uniq -f 2 -c
复制代码



3. 再对上一步结果按照出现次数的倒序排列

cat uniq_demo.txt | sort -k 3 | uniq -f 2 -c | sort -nr
复制代码



霍格沃兹的测试管理班是专门面向测试与质量管理人员的一门课程,通过提升从业人员的团队管理、项目管理、绩效管理、沟通管理等方面的能力,使测试管理人员可以更好的带领团队、项目以及公司获得更快的成长。提供 1v1 私教指导,BAT 级别的测试管理大咖量身打造职业规划。


用户头像

测试人

关注

专注于软件测试开发 2022-08-29 加入

霍格沃兹测试开发学社,测试人社区:https://ceshiren.com/t/topic/22284

评论

发布
暂无评论
软件测试学习笔记丨Linux命令 uniq去重_软件测试_测试人_InfoQ写作社区