Linux classes on the assignment Wednesday, if there is a poor consideration to the place, please do not hesitate to enlighten.
Shell Processing Text See this blog for related frequently used commands
#
#假设输入两个參数 is the first to count the number of words. The second article to be counted
#假设输入一个參数 the default count of words is 10
#
Detailed ideas:
Replacing various symbols with newline (tr command)
Uppercase to lowercase (tr command)
Sort, count the number of words and remove repetition (sort and uniq)
Sort by the high and low number of occurrences (sort)
Print n A word that needs to be counted
#!/bin/bashif [$#-ne 2-a $#-ne 1]; then echo "Usage: ' basename $ ' [n] Input file" echo exitfiif [$#- EQ 1];then i_top=10 i_file=$1fiif [$#-eq 2];then i_top=$1 i_file=$2fitr-sc "[A-z][a-z]" " [\012 *] " < $I _file | TR "[A-z]" "[A-z]" | sort | uniq-c | Sort -k1-n-R | head-$I _top | nl
Linux Jobs (iii)-shell statistics The most frequently occurring n words in an article and sorts the number of output occurrences