Shell编程之统计英文文本的单词及频数
2017-05-26 17:59
411 查看
#! /bin/bash
if [ $# -gt 1 ]
then
echo "The lot of parameters is more than the rule" #如果参数超过一个输出错误提示
else
{
touch buff.txt #创建缓冲文件
if [ -f"$1" ] #判断是否为普通文件
then
echo "The massages is: "
echo " This is a simple file."
fi
cat $1 | while read line #将目标文件按行读取,最后一行读取后退出
while do
for word in $line
do
echo -e $word >> buff.txt #将读取的每行word分行(-e)送到缓冲文件buff.txt中
done
done
var=$(cat buff.txt | wc -w) #将统计单词数的结果给var变量
echo " The file have $var words."sort -d buff.txt | uniq -c | sort -r #按字典(-d)排序后去重并显示频数rm buff.txt #删除缓冲文件
}
fi
if [ $# -gt 1 ]
then
echo "The lot of parameters is more than the rule" #如果参数超过一个输出错误提示
else
{
touch buff.txt #创建缓冲文件
if [ -f"$1" ] #判断是否为普通文件
then
echo "The massages is: "
echo " This is a simple file."
fi
cat $1 | while read line #将目标文件按行读取,最后一行读取后退出
while do
for word in $line
do
echo -e $word >> buff.txt #将读取的每行word分行(-e)送到缓冲文件buff.txt中
done
done
var=$(cat buff.txt | wc -w) #将统计单词数的结果给var变量
echo " The file have $var words."sort -d buff.txt | uniq -c | sort -r #按字典(-d)排序后去重并显示频数rm buff.txt #删除缓冲文件
}
fi
相关文章推荐
- 统计英文文本文档中前十个出现频率最多的单词
- 统计一个字符串中各个英文单词的出现的频数
- 输入一段英文文本,用程序统计出现频率最高和最低的两个单词;
- 使用单链表统计英文文本单词个数
- c++ 统计英文文本中每个单词的词频并且按照词频对每行排序
- 统计一个字符串中各个英文单词的出现的频数
- 统计一个英文文本的单词出现的频率(有标点符号的)
- C#统计英文文本中的单词数并排序
- 编程统计一个英文文本文件中单词词频
- Java 文件统计:编写程序,统计英文文本文件中的字符数目和单词数目。程序运行时,输入要统计的文件的名称,程序处理后输出字符数目和单词数目
- 统计一个英文文本的单词词频
- 编译器DIY之———统计英文文本中的单词数,字符数和行数
- 统计文本英文单词总个数,并列出每个单词的个数
- 统计英文文本单词出现频率
- 统计一篇英文文章中单词出现的频数
- c++ 统计英文文本中每个单词的词频并且按照词频对每行排序
- 基于bf算法统计文本中某个单词出现的频率
- Linux 统计文本的单词数
- 统计文本关键词频数
- 实验四-1 统计文本单词的个数