In the spirit of short scripts I needed another version of FINDit like you may see in my PowerShell post. Here is that very thing in BASH/ZSH
findit()
{
#$1 is the path to search for a string
#$2 is the string to search and find
usage()
{
echo " -- Usage for findit ---
\$1 is the path to search for a string
\$2 is the string to search and find
__________________________
example: findit $HOME/.zshrc powerlevel10k
output: /Users/thom.schumacher/.zshrc:10:ZSH_THEME=\"powerlevel10k/powerlevel10k\"
/Users/thom.schumacher/.zshrc:50:source ~/powerlevel10k/powerlevel10k.zsh-theme
__________________________"
}
if [ -z "$1" ] || [ -z "$2" ]; then
echo >&2 'Need 2 parameters which are not empty'
usage
return 1
fi
grep -rnw "$1" -e "$2"
}
findit . echo
This will search from your current directory and tell you ever file that it finds the word Echo in.
with the filename and the line it found it.