You should be able to do all the substitutions in one sed
command, and it can also filter out com/foo
. Then pipe the output to a while read
loop.
git ls-files | grep .java |
sed -e '/com\/foo/d' -e 's/\(.java[^/]*\).java/\1/' -e 's/com\/old\/old/com\/new/' -e 's/\(.*\)\/.*/\1/' |
uniq | while read path; do
mkdir -p "$path"
done
Here's how to do your git mv
:
git ls-files | grep .java |
sed -e '/com\/intuit/d' -e 's/\(.java[^/]*\).java/\1/' | uniq |
while read path; do
dir=$(echo "$path" | sed -e 's/com\/old\/old/com\/new/' -e 's/\(.*\)\/.*/\1/')
mkdir -p "$dir"
git mv "$path" "$dir"
done