Shell statistics Word Frequency script

Source: Internet
Author: User
Tags egrep

  

#!/bin/bashif [$#-ne 1];then        echo "usage:$0 filename";        Exit-1fifilename=$1egrep-o "\b[[:alpha:]]+\b" $filename | awk ' {count[$0]++}end{printf ("%-14s%s\n", "Word", "Count"), for (Ind in count) {printf ("%-14s%d\n", Ind,count[ind]);}} '

Two points to note here.

The difference between Egrep and grep: The EGREP supports a more complete

\b

The symbol \b
Matches the empty string at the edge of a word matches a word boundary

\< \>

The symbols \< and \> respectively match the empty string at the beginning and end of a word. Match the beginning or end of a word with an empty string

%-14s-Indicates that left-justified 14 indicates a string width of 14


Shell statistics Word Frequency script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.