0

I have a text file with many lines like -

The quick brown fox jumps over the lazy dog
The quick brown fox did not jumps over the lazy dog
The quick brown fox may jumps over the lazy dog
The quick brown fox may not jumps over the lazy dog
anything can happen
nothing can happen

I want to get the count of occurrences in lines where both 'fox' and 'jumps' comes.

Tried grep -ci "$word1|word2' $file but this is not working

2 Answers 2

2

You can pipe grep to grep, only doing the count on the second instance of grep like so:

grep -i fox $file | grep -ci brown

Alternatively you can use egrep which is the same as grep -E, and use a regular expression:

egrep -ci 'fox.*brown|brown.*fox' $file
-1
echo -e "fox:$(grep -c fox aaa)\njumps:$(grep -c jumps aaa)"

aaa : your file name

and your command wrong

grep -ci "fox\|jumpsa" aaa

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .