Multiple keyword search in multiple directories bash script

Multiple keyword search in multiple directories bash script

I guess the title is good enough :)
Probably you can do it in single grep command too.. but this way you will play with bash as well..

here is the bash script doing it


 #! /bin/bash
 dirs=(dir1 dir2 dir3 dir4 dir5)
 keywords=(keyword1 keyword2 keyword3 keyword4 keyword5)
 strs=""
 for word in "${keywords[@]}"; do
     strs+=" -e ${word} "
 done
 
 for path in "${dirs[@]}"; do
     dirname="$(basename "${path}")"
     grep -ir --color ${strs} ${path}
 done

Save this as finder.sh

and you can run it as bash finder.sh

See more on bash here

multiple file upload in Symfony2 example

Bash directories coloring lost in unix when using ls

[: too many arguments error in bash script

Regular expression for file and directory listing

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*