I wrote this script which counts occurrences of particular pattern in a given file. However if text file contains square brackets or curly braces shell outputs a message "Missing }". Here is the script:
#!/bin/csh
@ count=0
foreach word ( `cat test` )
if (`echo $word | egrep -c 'int'`) then
@ count= $count + 1
endif
end
echo $count