I want to count the occurrence of a pattern per line and also get the last matching line number
So for counting patterns I would use
grep -c pattern file
and for last matching line number
grep -n pattern file | cut -d : -f 1 | tail -1
Is there any way by which I get both the results by greping only once? The file I am working with is large and I need to iterate this for several patterns, so I would like to avoid greping twice.