搜索,匹配&从输入文件计数:脚本

时间:2015-09-01 04:58:16

标签: perl shell awk sed gawk

我有一个像这样的输入文件

John completed his graduation 
John is working for an IT industry
Thomas completed his graduation
John completed his graduation
Thomas is working for an IT industry
Thomas is working for an IT industry

我想要一个像这样的输出

John word has 2 Graduations
Thomas word has 2 IT industry

任何人都可以帮助我吗

2 个答案:

答案 0 :(得分:0)

Perl中的解决方案

print image.shape

Demo

注意:可以根据文件中数据的知识来改进正则表达式。

答案 1 :(得分:0)

也许你可以做这样的事情并努力用你的选择替换这些词

sort file | uniq -c | sort -k2,2 -k1,1r | awk '!a[$2]++{print $2, "word has", $1, $NF}'

John word has 2 graduation
Thomas word has 2 industry

对文件进行排序,查找每个文件的计数,为每行记录最高计数并打印。