Last active
October 19, 2018 14:35
-
-
Save DanLaufer/9c8746a4756a8c18227bc30062e02778 to your computer and use it in GitHub Desktop.
Bash - Function to check for an odd number of occurances of a string in a file
This file contains hidden or 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
# $1 is the name of the element to search | |
# $2 is the file to search | |
function checkodd(){ | |
if [ $# -ne 2 ]; then | |
echo "Please use the following format: checkodd <string to check> <location>" | |
else | |
for f in "$2"/* "$2"/**/* ; do | |
if [ -f "$f" ]; then | |
stringcount=$(grep -o $1 $f | wc -l) | |
if [ $((stringcount % 2)) -eq 1 ]; then | |
echo $stringcount' '$1': '$f | |
fi | |
fi | |
done; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment