I have the following problem: I want to count migration files per directory.
My structure always looks like this:
/some/path/app1/migrations/0001_hello_world.py
/some/path/app2/migrations/0001_foo.py
/some/path/app2/migrations/0002_bar.py
What I need is a shell script, in the best case a one-liner to get the following result:
app1: 1
app2: 2
So I get the numbers of files per app directory.
I got as far as getting my list of files:
git diff --color --name-only --diff-filter=A origin/develop my-branch | grep "\/migrations\/[0-9]"
I can count all of those matches with wc -l
but I cannot count per directory.
Unfortunately even with google and stack, I'm stuck.
Any ideas on that topic?
git diff
? – Ron Jun 13 '19 at 14:35for folder in *; do echo "$folder: "; git diff --color --name-only --diff-filter=A origin/develop my-branch | find ./$folder -type f | wc -l; done | grep -A 1 "dir"
– Dr-Bracket Jun 13 '19 at 14:38"dir"
be? sorry, not so familiar with shell scripting :( – Ron Jun 13 '19 at 14:41