I have this little script that puts out some dir paths. I want to mkdir all those paths.
for filename in $(git ls-files | grep .java | grep -v 'com/foo' | sed -e 's/\(.java[^/]*\).java/\1/' | uniq)
do
echo "$filename" | sed -e 's/com\/old\/old/com\/new/' | sed 's/\(.*\)\/.*/\1/'
done
So new dir are created... com/old/old = com/new
But I cannot get that mkdir to work... I tried..
path=$("$filename" | sed -e 's/com\/old\/old/com\/new/' | sed 's/\(.*\)\/.*/\1/')
mkdir -p "$path"
That is just messing with the file contents.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With