To find number of occurrences of a word taken as input from command line in unix

后端 未结 3 1675
孤城傲影
孤城傲影 2021-01-27 18:08

For the file file1.txt which contains

Apple fruit Apple tree
Tree AApple AApklle Apple apple
TREE
Apple

I want to find number of o

3条回答
  •  情深已故
    2021-01-27 18:55

    You can change the grep line to:

    grep -o '\<'"$TOFIND"'\>' "$FILE" | wc -l
    

    or just:

    grep -o "\<$TOFIND\>" "$FILE" | wc -l
    

    Then it will work. It's because the quotes, your double quotes was quoted inside single quotes, so they are not expanded.

提交回复
热议问题