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