Created
December 27, 2018 18:03
-
-
Save augustohp/86b277b168a1f19d82b4f9c8268f2643 to your computer and use it in GitHub Desktop.
List docker-compose.yml ports being used in all repositories inside the current directory
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
#!/usr/bin/env sh | |
# vim: ft=sh: | |
# Usage: list_docker_compose_files [pattern] | |
list_docker_compose_files() | |
{ | |
pattern=${1:-"docker-compose.yml"} | |
find . -name "${pattern}" -type f | |
} | |
for file in $(list_docker_compose_files) | |
do | |
grep --after-context 1 --with-filename "ports:" $file \ | |
| grep -v "ports:" \ | |
| sed s/[^0-9:]//g \ | |
| cut -d: -f 1 \ | |
| awk "BEGIN{FILE=\"${file##./}\"; OFS=\"\t\"; FIELDWIDTHS=\"10 70\"}{ if (\$1!=\"\") {print \$1,FILE}}" | |
done | sort -n | sed -r /^s*$/d | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment