uniq

uniq命令使用说明

陌路散爱 提交于 2019-12-02 05:32:15
1、命令概述 uniq命令全称是“unique”,中文释义是“独特的,唯一的”。该命令的作用是用来去除文本文件中连续的重复行,中间不能夹杂其他文本行。去除了重复的,保留的都是唯一的,也就是独特的,唯一的了。 我们应当注意的是,它和sort -u的区别,sort -u只要有重复行,它就去除,而uniq重复行必须要连续,也可以用它忽略文件中的重复行。 2、命令语法 uniq【选项】 【文件】 3、命令选项 -c, --count #在每行前加上表示相应行目出现次数的前缀编号 -d, --repeated #只输出重复的行,每个重复纪录只出现一次 -D, --all-repeated #只输出重复的行,不过有几行输出几行 -f, --skip-fields=N #-f 忽略比较指定的栏位;,-f 1 忽略第一列 -i, --ignore-case #不区分大小写 -s, --skip-chars=N #根-f有点像,不过-s是忽略, -s 5就表示忽略最前面的5个字符(包括空格) -u, --unique #只显示没有重复的纪录,根mysql的distinct功能上有点像, -z, --zero-terminated #在末尾使用\0,而不是换行符。 -w, --check-chars=N #对每行第N 个字符以后的内容不作对照,指定要比较的字符。 4、命令示例 4.1

awk to remove duplicate rows totally based on a particular column value

自闭症网瘾萝莉.ら 提交于 2019-12-02 02:10:08
I got a dataset like: 6 AA_A_56_30018678_E 0 30018678 P A 6 SNP_A_30018678 0 30018678 A G 6 SNP_A_30018679 0 30018679 T G 6 SNP_A_30018682 0 30018682 T G 6 SNP_A_30018695 0 30018695 G C 6 AA_A_62_30018696_Q 0 30018696 P A 6 AA_A_62_30018696_G 0 30018696 P A 6 AA_A_62_30018696_R 0 30018696 P A I want to remove all the rows if col 4 have duplicates. I have use the below codes (using sort, awk,uniq and join...) to get the required output, however, is there a better way to do this? sort -k4,4 example.txt | awk '{print $4}' | uniq -u > snp_sort.txt join -1 1 -2 4 snp_sort.txt example.txt | awk '

Linux 系统如何通过 netstat 命令查看连接数判断攻击

拈花ヽ惹草 提交于 2019-12-02 00:59:26
# 很多时候我们会遇到服务器遭受 cc 或 syn 等攻击,如果发现自己的网站访问异常缓慢且流量异常。可以使用系统内置 netstat 命令 简单判断一下服务器是否被攻击。常用的 netstat 命令 该命令将显示所有活动的网络连接。 #netstat -na 查看同时连接到哪个服务器 IP 比较多,cc 攻击用。使用双网卡或多网卡可用。 # netstat -an|awk '{print $4}'|sort|uniq -c|sort -nr|head 查看哪些 IP 连接到服务器连接多,可以查看连接异常 IP。 #netstat -an|awk -F: '{print $2}'|sort|uniq -c|sort -nr|head 显示所有 80 端口的网络连接并排序。这里的 80 端口是 http 端口,所以可以用来监控 web 服务。如果看到同一个 IP 有大量连接的话就可以判定单点流量攻击了。 #netstat -an | grep :80 | sort 这个命令可以查找出当前服务器有多少个活动的 SYNC_REC 连接。正常来说这个值很小,最好小于 5。 当有 Dos 攻击或的时候,这个值相当的高。但是有些并发很高的服务器,这个值确实是很高,因此很高并不能说明一定被攻击。 #netstat -n -p|grep SYN_REC | wc -l 列出所有连接过的 IP 地址

Advanced `uniq` with “unique part regex”

不想你离开。 提交于 2019-12-01 23:50:00
问题 uniq is a tool that enables once to filter lines in a file such that only unique lines are shown. uniq has some support to specify when two lines are "equivalent", but the options are limited. I'm looking for a tool/extension on uniq that allows one to enter a regex. If the captured group is the same for two lines, then the two lines are considered "equivalent". Only the "first match" is returned for each equivalence class. Example : file.dat : foo!bar!baz !baz!quix !bar!foobar ID!baz! Using

Perl way of using cut,grep,uniq [closed]

↘锁芯ラ 提交于 2019-12-01 15:31:37
I am running a Perl script inside a Perl script, and the output of the script is something like this # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/angyvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/aqmmgvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/69aqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/69aavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW

Perl way of using cut,grep,uniq [closed]

做~自己de王妃 提交于 2019-12-01 13:36:18
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am running a Perl script inside a Perl script, and the output of the script is something like this # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/angyvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/aqmmgvqnqth/rmn/cqqqa

Shell 编程 排序工具 sort 和 uniq

只谈情不闲聊 提交于 2019-12-01 10:39:56
本篇主要写一些 shell 脚本排序工具的使用。 sort 概述 sort 是一个以行为单位对文件内容进行排序的工具,也可以根据不同的数据类型来排序。 用法 sort [选项] 参数 -f :忽略大小写 -b :忽略每行前面的空格 -M :按照月份进行排序 -n :按照数字进行排序 -r :反向排序 -u :等同于 uniq ,表示相同的数据仅显示一行 -t :指定分隔符,默认使用 Tab 键分隔 -o <输出文件> :将排序后的结果转存至指定文件 -k :指定排序区域 示例 将 /etc/passwd 文件中的账号进行排序 [root@localhost ~]# sort /etc/passwd adm:x:3:4:adm:/var/adm:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin

Why does “uniq” count identical words as different?

白昼怎懂夜的黑 提交于 2019-11-30 21:11:52
I want to calculate the frequency of the words from a file, where the words are one by line. The file is really big, so this might be the problem (it counts 300k lines in this example). I do this command: cat .temp_occ | uniq -c | sort -k1,1nr -k2 > distribution.txt and the problem is that it gives me a little bug: it considers the same words as different. For example, the first entries are: 306 continua 278 apertura 211 eventi 189 murah 182 giochi 167 giochi with giochi repeated twice as you can see. At the bottom of the file it becomes even worse and it looks like this: 1 win 1 win 1 win 1