Findit BASH Version


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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s