grep -P is doesn't work on a mac. The solution to this is to install gnu grep with: brew install grep and then used ggrep in the scripts instead of grep.