Skip to content

Instantly share code, notes, and snippets.

@santicalvo
Created April 11, 2018 05:58
Show Gist options
  • Select an option

  • Save santicalvo/3719a87a67de10a2ae258d506fb4196f to your computer and use it in GitHub Desktop.

Select an option

Save santicalvo/3719a87a67de10a2ae258d506fb4196f to your computer and use it in GitHub Desktop.
Find number of ocurrences of string recursively in bash
#!/usr/bin/env bash
# We require two arguments: folder to search and word
ocurrences=$(find $1 -type f -exec grep -io $2 {} \; | wc -l)
if [ "$ocurrences" -gt 0 ];then
echo "more than 0: $ocurrences"
else
echo "No ocurrences: $ocurrences"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment