0

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?

1
  • 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, 2009 at 4:28

3 Answers 3

1

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
0

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.

2
  • That doesn't take into consideration the possibility of the string appearing twice on a line.
    – EEAA
    Dec 3, 2009 at 4:28
  • Your right ... that'll teach me to post while trying to listen to s conference call.
    – Zypher
    Dec 3, 2009 at 5:37
0

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.

You must log in to answer this question.

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