Last active
August 29, 2015 14:03
-
-
Save ormaaj/56648862739d597cd0b1 to your computer and use it in GitHub Desktop.
Directory merge / rename example
This file contains 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 ksh | |
# Example for merging directories of files with possibly | |
# overlapping names into a single directory. | |
mkdir a b c new | |
touch a/{0..5} b/{3..7} c/{4..10} | |
echo before: */* | |
typeset -A files | |
for x in ~(N)./*/*; do | |
files[${x##*/}]+=("${x}") | |
done | |
for x in "${!files[@]}"; do | |
n=0 | |
for y in "${files[$x][@]}"; do | |
mv -f -- "$y" "new/${y##*/}.$((n++))" | |
done | |
done | |
echo after: new/* |
This file contains 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
before: a/0 a/1 a/2 a/3 a/4 a/5 b/3 b/4 b/5 b/6 b/7 c/10 c/4 c/5 c/6 c/7 c/8 c/9 | |
after: new/0.0 new/1.0 new/10.0 new/2.0 new/3.0 new/3.1 new/4.0 new/4.1 new/4.2 new/5.0 new/5.1 new/5.2 new/6.0 new/6.1 new/7.0 new/7.1 new/8.0 new/9.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment