If you want to get count of a specific pattern/text in a file, then following Bash Command would solve your problem; let's try to understand this with the help of an example:
Let's say, we want to get count of pattern "Value(0)" in the following file named "Stats"
File Name: Stats
STATS Value(X) Mode 1 STATS Value(X) Mode 3 STATS Value(0) Mode 0 STATS Value(0) Mode 0 STATS Value(X) Mode 11 STATS Value(X) Mode 5 STATS Value(0) Mode 0
The command for performing this task would be:
grep -c "Value(X)" Stats
Displayed result will be: 3
So how this works! We used "GREP" utility with "-c" i-e "grep -c", this basically gives us the count of a pattern/text in any file, like it did in above example, it gave us correct count of pattern "Value(X)" in file named "Stats".
You might have to mention the file path in the command too, if you are not running the script in the same directory where file is placed.Contact Us for News Tips, Corrections and Feedback