Skip to content

Instantly share code, notes, and snippets.

@augustohp
Created December 27, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save augustohp/86b277b168a1f19d82b4f9c8268f2643 to your computer and use it in GitHub Desktop.
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
#!/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