Last active
March 27, 2019 19:49
-
-
Save jayers99/bb2bf37b029d7e3cbf972bbbf1fe2194 to your computer and use it in GitHub Desktop.
get all the directory names that contain some string
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
#!/bin/bash | |
# return a list of directories the contain given text | |
# example: ~/scripts/tfgrep_dirs.sh '^\s*source\s*=\s*.*some_module_name' | |
file_paths=$(grep -irlP --include \*.tf --exclude-dir=.terraform --exclude-dir=.git $@) | |
dirs_array=() | |
for i in $file_paths; do | |
dirs_array+=($(dirname $i)) | |
done | |
dirs_uniq=($(echo "${dirs_array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) | |
for i in "${dirs_uniq[@]}"; do | |
echo $i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment