Effective Word Count characters

Just before graduation, as there are words thesis requirements, so valid words written a simple script to count the text.

1. Because it is sh script, first check whether the system supports the command

    > which sh

Output: / bin / sh # NOTE The system supports sh command

 

2. The code is as follows :( filename: countNum.sh)

#! / bin / SH
# calculate a digital file, my test file is test.txt, needs according to their own changes to the file
# detect specific number of characters
count_spec = $ (echo "$ ( wc -w test. TXT) "| TR -cd" [0-9] ")
# number of text characters detected
count_all = $ (echo" $ ( wc -m test.txt) "| tr -cd" [0-9] ")

echo $(($count_all-$count_spec))
exit 0

 

3. Use

    sh countNum.sh

4. instructions

   The script can count the number of words .txt file, has not been tested for other files, after all, the codec files are different

Guess you like

Origin www.cnblogs.com/haibiscuit/p/shell.html