Created
March 19, 2016 20:17
-
-
Save astorije/e7d12ff484cbfc745ec1 to your computer and use it in GitHub Desktop.
Counts the number of occurrences of a given pattern recursively in the current directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e # Stop execution at first error | |
if [[ $# -eq 0 ]] ; then | |
echo "Usage: $(basename $0) pattern" | |
echo " Counts the number of occurrences of a given pattern recursively" | |
echo " in the current directory." | |
exit 1 | |
fi | |
grep "${1}" -I --recursive . | # -I Ignore binary files | |
cut -d ':' -f1 | # -d Field delimiter | |
# -f1 First field | |
uniq | | |
wc -l | # -l Number of lines | |
awk '{print $1}' # Only print the integer without whitespaces |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment