uniq

Calculate Word occurrences from file in bash

柔情痞子 提交于 2019-11-30 10:00:42
I'm sorry for the very noob question, but I'm kind of new to bash programming (started a few days ago). Basically what I want to do is keep one file with all the word occurrences of another file I know I can do this: sort | uniq -c | sort the thing is that after that I want to take a second file, calculate the occurrences again and update the first one. After I take a third file and so on. What I'm doing at the moment works without any problem (I'm using grep , sed and awk ), but it looks pretty slow. I'm pretty sure there is a very efficient way just with a command or so, using uniq , but I

Why does “uniq” count identical words as different?

流过昼夜 提交于 2019-11-30 05:16:15
问题 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

linux应急响应常用命令

若如初见. 提交于 2019-11-30 02:19:34
端口查看 netstat -anplt | more 查看进程: ps -ef ps aux ps aux | grep pid 定时任务查看 crontab 查看文件 cat file全显示 head -5 file //显示前5行 tail -5 file //显示后5行 t00ls大佬分享的技巧1、定位有多少IP在爆破主机的root帐号: grep "Failed password for root" /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr | more 定位有哪些IP在爆破: grep "Failed password" /var/log/secure|grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"|uniq -c 爆破用户名字典是什么? grep "Failed password" /var/log/secure|perl -e 'while($_=<>){ /for(.*?) from/;

测试效率加倍提升!shell 高阶命令快来 get 下!

删除回忆录丶 提交于 2019-11-29 21:44:13
背景 目前大部分的项目都是部署在Linux系统上,作为测试,掌握常用Linux命令是必须的技能。很多的工作了好几年的测试人员可能还只会简单的ls、cd、cat等等这些命令,这些命令是可以应付工作的大部分场景。但是真正要提升测试效率、提高自己的核心竞争力,这些还是远远不足的。在测试工作中很多情况下我们需要同文本文件打交道,如分析/统计日志、自动化部署等等,今天给大家介绍几个很实用的高阶文本处理命令。 cut 此命令的主要作用是来选取一段内容中我们想要获取的,通常选择信息是针对与“行”来分析的,擅长处理“以一个字符间隔”的文本内容。 语法格式: $ cut -c 字符区间 $ cut -d “分隔字符” -f fields 参数 说明 -c 以字符为单位进行分割 -d 自定义分隔符,默认为制表符 -f 与-d一起使用,指定显示哪个区域 示例: 新建练习文件,内容如下 [root@localhost shellTest]# cat test.txt 01 nick 20 02 rose 25 03 jack 30 04 tom 27 1、显示每行第四个字符之后的内容 [root@localhost shellTest]# cut -c 4- test.txt nick 20 rose 25 jack 30 tom 27 #说明: # 4- 表示从第4个字符开始 # 4-10

Linux -- uname命令查询操作系统

别来无恙 提交于 2019-11-29 16:11:58
Ubuntu版本查看:cat /etc/issue RedHat版本查看:cat /proc/version 用命令lsb_release -a可以查看Ubuntu和RedHat的版本 (似乎是有管理员权限的才可以看。。。) 用命令 lscpu 可以查看Sockets,物理插槽。 1 查看CPU   1.1 查看CPU个数   # cat /proc/cpuinfo | grep "physical id" | uniq | wc -l   2   **uniq命令:删除重复行;wc –l命令:统计行数**   1.2 查看CPU核数   # cat /proc/cpuinfo | grep "cpu cores" | uniq   cpu cores : 4   1.3 查看CPU型号   # cat /proc/cpuinfo | grep 'model name' |uniq   model name : Intel(R) Xeon(R) CPU E5630 @ 2.53GHz   总结:该服务器有2个4核CPU,型号Intel(R) Xeon(R) CPU E5630 @ 2.53GHz   2 查看内存   2.1 查看内存总数   #cat /proc/meminfo | grep MemTotal   MemTotal: 32941268 kB //内存32G 1.

Calculate Word occurrences from file in bash

为君一笑 提交于 2019-11-29 15:38:18
问题 I'm sorry for the very noob question, but I'm kind of new to bash programming (started a few days ago). Basically what I want to do is keep one file with all the word occurrences of another file I know I can do this: sort | uniq -c | sort the thing is that after that I want to take a second file, calculate the occurrences again and update the first one. After I take a third file and so on. What I'm doing at the moment works without any problem (I'm using grep , sed and awk ), but it looks

awk除去重复行

ぃ、小莉子 提交于 2019-11-29 04:55:32
awk去除重复行,思路是以每一行的$0为key,创建一个hash数组,后续碰到的行,如果数组里已经有了,就不再print了,否则将其print 测试文件: 用awk: 用sort+uniq好像出错了: 到底是为什么uniq出错了呢?不知道,但是awk真的很强大。两者的差异还在于,awk保持了文件中原本的每行的顺序,而sort必须排序,这样就变成按字母或某种其他规则的排序了。 PS:uniq出错好像是因为\r\n的问题。 PS:错了。有的教程上,uniq -u就跟uniq是一样的。我用cygwin,uniq- u只显示不重复行,uniq则显示所有行,只不过去除重复。 来源: http://www.cnblogs.com/beautiful-code/p/5783520.html

linux网络命令 vconfig ifconfig

强颜欢笑 提交于 2019-11-28 22:28:45
apache启动、停止、重启命令 Udo apt - get install 软件名 安装软件命令 ls 列出当前目录文件(不包括隐含文件) ls -a 列出当前目录文件(包括隐含文件) ls -l 列出当前目录下文件的详细信息 cd .. 回当前目录的上一级目录 cd - 回上一次所在的目录 cd ~ 或 cd 回当前用户的宿主目录 pstree pstree -p可以帮你显示进程树。(可以查看进程父子关系) xargs 一条Unix和类Unix操作系统的常用命令。它的作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题。 find /path -type f -print0 | xargs -0 rm pgrep 和 pkill 用来找到或是kill 某个名字的进程。 (-f 选项很有用). kill 要挂起一个进程,使用 kill -STOP [pid]. 使用 man 7 signal 来查看各种信号,使用kill -l 来查看数字和信号的对应表 kill -l HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR

Rails 3, ActiveRecord, PostgreSQL - “.uniq” command doesn't work?

余生颓废 提交于 2019-11-28 09:06:43
I have following query: Article.joins(:themes => [:users]).where(["articles.user_id != ?", current_user.id]).order("Random()").limit(15).uniq and gives me the error PG::Error: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list LINE 1: ...s"."user_id" WHERE (articles.user_id != 1) ORDER BY Random() L... When I update the original query to Article.joins(:themes => [:users]).where(["articles.user_id != ?", current_user.id]).order("Random()").limit(15)#.uniq so the error is gone... In MySQL .uniq works, in PostgreSQL not. Exist any alternative? As the error states for

xargs、sort、uniq命令

為{幸葍}努か 提交于 2019-11-28 06:29:02
xargs、sort、uniq命令,我们由LeetCode的一道题来引入,并使用加以理解; 题目是这样的:写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率。 words.txt的内容为: the day is sunny the the the sunny is is 1.cat words.txt | sort 来看下会是什么效果 [root@Server-n93yom tmp]# cat words.txt | sort the day is sunny the the the sunny is is sort 命令将以默认的方式将文本文件的第一列以ASCII 码的次序排列,并将结果输出到标准输出。 2.使用 cat words.txt | xargs -n1 | sort | uniq -c 看下是什么效果 [root@Server-n93yom tmp]# cat words.txt | xargs -n1 | sort | uniq -c 1 day 3 is 2 sunny 4 the uniq命令只能对相邻行进行去重复操作,所以在进行去重前,先要对文本行进行排序,使重复行集中到一起,这就是为什么要先sort的原因;-c 是统计数量 3.使用 cat words.txt | xargs -n1 | sort | uniq -c |