The problem is .. lets say i have 600 files in a directory. All 600 files are shell script files. Now i need to find out the files which contains a pattern "SHELL" more than once.
No matter how the pattern occurs , it can be in same line or in different lines also.
I hope there must be some fair way to do this. Please help me.
Ah yes, you are right, grep -c only counts the number of lines which match the pattern.
Assuming the pattern is supposed to be a word token, you could do something like
for f in directory/*; do
tr '\011\040' '\012' <"$f" | grep -c SHELL | grep -v '^[01]$' >/dev/null && echo "$f"
done
The idea is to split each token onto a separate line, and then the number of matching lines will be equal to the number of occurrences of the token.
Different versions of tr have slightly different syntax; the first argument should be a tab and a space, and the second argument should be a newline. I'm using octal here because it's unambiguous, but not all versions of tr support that notation. Check the manual page of yours. If you need to pass in literal strings, it would look like
tr ' ' '
'
where you probably have to type something like ctrl-v tab to write a literal tab. And yes, a newline in single quotes is a valid and useful string in shell syntax.
How can I grep or find the pattern ^M from this files in the directory. I have couple of ascii files too.I have to grep the binary files.Please assist me
You might not get many replies because this thread has already been replied to for the original problem, and it doesn't appear that your question is directly related to multiple patterns.