Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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

Or

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

 
discard

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.