How count the number of two words associated with the two words occurring in the file?

Hi ,

I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying:[code] grep "error" log.txt | wc -l

No need to do wc -l where you are using grep as you can use grep -c

You could grep twice, for example:

grep -i error log.txt | grep -ic index.js

AWK Approach:

awk 'BEGIN{IGNORECASE = 1};/error/&&/index.js/{f++};END{print f}' log.txt
1 Like