U uCsDNerd Senior member Mar 3, 2001 338 0 0 Mar 16, 2002 #1 hey guys. In the sh shell, how could i find the number of times a pattern comes up in a file? thanks.
hey guys. In the sh shell, how could i find the number of times a pattern comes up in a file? thanks.
S skriefal Golden Member Apr 10, 2000 1,424 3 81 Mar 16, 2002 #2 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.
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.