功能:
1. 检查参数个数;
2. 检查input file是否存在;
3. 列出input file中出现频率最高的10个单词;
4. 列出这10个单词所在的行数和句子内容;
5. 手动输入input string, 在input file中查询string并记录。
-
-
-
- ARGNO=1
- E_WRONGARGS=65
- temp="tempfile"
- output="freout.txt"
-
- rm $output
-
-
- if [ $
- then
- echo "Parameter error. Expecting only $ARGNO parameter(s)."
- exit $E_WRONGARGS
- fi
-
-
- filename=$1
- if [ -e $filename ]; then
- echo "Input file is $filename."
- else
- echo "File $filename could not be found. Please check!"
- exit $E_WRONGARGS
- fi
-
-
- printf "(1) Here are 10 most frequent words in file $filename:\n" > $output
- cat $filename | sed -e "s/[^a-zA-Z]/\n/g" | grep -v ^$ | sort | uniq -c | sort -n -k 1 -r | head -10 > $temp
- cat $temp >> $output
- printf "\n(2) Lists of words:\n" >> $output
- for x in $(awk '{print $NF}' $temp)
- do
-
- printf "\n[$x]:\n" >> $output
- grep -En "\b$x\b" $1 >> $output
- done
-
- printf "\n(3) To search what you want?\n" >> $output
- echo "To search what you want? Please input your word!"
- read input
- while [ "$input" != "exit" ]
- do
- if [ "$input" != "exit" ]
- then
- printf "\nsearch for [$input]:\n" >> $output
- grep -En "\b$input\b" $1 | tee -a $output
- echo -e | tee -a $output
- echo "Continue? Please input your word. (To stop by using 'exit'.)"
- read input
- fi
- done
- echo -e
- echo "Exit of searching."
-
- rm $temp
总结:(空了来写)
1. 学习command?
2. 参考?
阅读(568) | 评论(1) | 转发(0) |