Little Girl's Mostly Linux Blog

CountEverything

Count everything

This page was last updated on November 09, 2009.

Lines

  • This command shows the number of lines in a file:
    wc -l filename
    • Example:
    • wc -l /etc/fstab
    • Result:
    • 12 /etc/fstab

Words

  • This command shows the number of words in a file:
    wc -w filename
    • Example:
    • wc -w /etc/fstab
    • Result:
    • 58 /etc/fstab

Characters

  • This command shows the number of characters in a file:
    wc --chars filename
    • Example:
    • wc --chars /etc/fstab
    • Result:
    • 661 /etc/fstab

Lines, words, characters

  • This command shows the number of lines, words, and characters in a file:
    wc filename
    • Example:
    • wc /etc/fstab
    • Result:
    • 12  58 661 /etc/fstab

Show frequency of use of all words in a text file

  • This command shows the frequency of use of all words in a text file.

    • Replace SOURCEFILE with the name of your text file, and RESULTFILE with the name of the text file you’d like the results to be saved to:
    • cat SOURCEFILE | tr A-Z a-z | tr -cs a-z '\n' | sort | uniq -c | sort -rn > RESULTFILE

Show frequency of use of specific words in a text file

  • With this method, you create a text file containing a list of specific words, placing one word per line in the file. You then run the command below to use the word list to check the frequency of use of those words in any text file.

    • Replace SOURCEFILE with the name of your text file, WORDLISTFILE with the name of word list file, and RESULTFILE with the name of the text file you’d like the results to be saved to:
    • cat SOURCEFILE | tr A-Z a-z | tr -cs a-z '\n' | grep -w -F -f WORDLISTFILE | sort | uniq -c | sort -rn > RESULTFILE


Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: