Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a very large log file I have entries like :

FLOW ENTERING somecompany.somepackage.datacontrol.provider.DataProvider@c37ae61.release()

The only change between what differs between entries is the string after the @ and before .release()(The bolded portion).

There are other entries like the following which needs to be discarded in the search:

FLOW ENTERING somecompany.somepackage.datacontrol.provider.DataProvider@c37ae61.somethingelse()

So my search pattern should end with .release().

How can I know the number of such occurrences in the log file(the number of matching lines) and also print out all the matching patterns?

P.S: I am using Linux environment.

share|improve this question
You should clarify, what you want to count: The number of matching lines or the number of occurrences of each unique string between @ and .release(). – neocrow Mar 24 '14 at 11:21
@neocrow I want to count the number of matching lines. – Geek Mar 24 '14 at 11:40
up vote 1 down vote accepted

I think grep -c option is exclusive - it's not possible to combine the -c option with another option to output matching lines AND a count. So using tee outputs the matches AND write the matches to a temporary file then count the lines in the file.

grep 'FLOW ENTERING.*release()' k  | tee /tmp/grep.tmp && wc -l /tmp/grep.tmp
share|improve this answer
What is the tee command doing here? Can you put some explanation? – Geek Mar 24 '14 at 18:50
tee takes the output (in this case from grep) and outputs it to the screen AND writes the output to a file /tmp/grep.tmp (so that wc can count the number of matches). – suspectus Mar 24 '14 at 22:35

you can use grep '.release()' file|wc -l

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.