Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

say I have a file in on a unix server, I want to count the number of occurances of .dll or say .exe in the file.

how can I do this?

share|improve this question
Strange question. Are you looking for a simple character search or actual dependence list of what .dll's your .exe calls. I was not aware that .exes run on unix and call .dlls. Of couse a windows system can access a unix drive share and load .exes from it. Pls clarify – kingchris Dec 3 '09 at 4:28

Give this a try (assuming that it's a text file):

grep -o '.dll' filename | wc -l

If it's a binary file, try:

grep -binary-files=text -o '.dll' filename | wc -l


strings filename | grep -o '.dll' | wc -l
share|improve this answer

You can do grep -c .dll <file> (as dennis said) grep -o <file> | wc -l just change '.dll' to whatever you feel like searching for.

share|improve this answer
That doesn't take into consideration the possibility of the string appearing twice on a line. – EEAA Dec 3 '09 at 4:28
Your right ... that'll teach me to post while trying to listen to s conference call. – Zypher Dec 3 '09 at 5:37

Use this:

perl -lne '$c++while/[.]dll/g;END{print$c}' <filename

You can modify the regular expression (/[.]dll/) in the middle to search for something else (see man perlre for details). If you want to search for something containing a newline, add -0777 after perl.

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.