You are not logged in.
i'm trying to write a script that will copy files from all directories below the pwd into the pwd and add a prefix of "[directory name]-" so that identically named files will not be overwritten and so i can still determine what group they belong to. doing something like:
for i in *; do for h in $i/*; mv $h ./$i-$h; done; done;
is obviously gonna be messed up because $h will expand to $directory/$file.
can anyone point me in the right direction to do this?
Offline
Try this:
for file in $(find -type f); do mv "$file" "$(echo $file | sed 's#^\.\(.*\)/#[\1]-#;s#/##g')"; done
Last edited by Gilneas (2007-11-12 03:39:21)
Offline
THANKS!
now i need to brush up on my sed skills and figure out whats happening there. thanks again.
Offline
Also, basename is your friend
for i in *; do for h in ${i}/*; mv ${h} ./${i}-$(basename ${h}); done; done;
Offline