sh shell programming help-

uCsDNerd

Senior member
Mar 3, 2001
338
0
0
hey guys.
In the sh shell, how could i find the number of times a pattern comes up in a file?

thanks.
 

skriefal

Golden Member
Apr 10, 2000
1,424
3
81
Use grep. i.e.:


<<
#!/bin/sh
NUMTIMES=`grep -c running ${1}`
echo "found ${NUMTIMES} matches."
>>


... would show how many times the word "running" appears in the specified file. Use grep -e or egrep if you need to search for regular expressions.