lose_spaces.sh

 

###
### lose_spaces.sh
###
### For every file beneath current directory
### rename file, replacing spaces with underscores.
###
###



echo "Removing parenthesis from directory names"
for x in `echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20`
do
    echo $x
    find . -type d -maxdepth $x  | grep ")" > tmp.sh
    sed -e "s/[()]//g" tmp.sh   | sed "s/^/ \"/" | sed "s/$/\" /"  > tmp1.sh
    paste tmp.sh tmp1.sh  | sed "s/^/mv \"/" | sed "s/	/\" /"  > tmp2.sh
    sh ./tmp2.sh 
done

echo "Removing files with imbedded dollar signs"
find . -name \* -print | grep "\\$"  | sed "s/\\$/\\\\$/g" > tmp.sh
sed "s/\\$/S/" tmp.sh | sed "s/\~\\\//" | sed "s/^/ \"/" | sed "s/$/\" /"  > tmp1.sh 
paste tmp.sh tmp1.sh  | sed "s/^/mv \"/" | sed "s/	/\" /"  > tmp2.sh
sh ./tmp2.sh 


echo "Removing parenthesis from file names"
find . -type f | grep "(" > tmp.sh
sed -e "s/[()]//g" tmp.sh   | sed "s/^/ \"/" | sed "s/$/\" /"  > tmp1.sh 
paste tmp.sh tmp1.sh  | sed "s/^/mv \"/" | sed "s/	/\" /"  > tmp2.sh
sh ./tmp2.sh 

echo "Removing spaces from directory names"
for x in `echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20`
do
    echo $x
    find . -type d -maxdepth $x  | grep " " > tmp.sh
    sed "s/'//g" tmp.sh | sed "s/ /_/g" | sed "s/^\.\///" | sed "s/\&/_/g" > tmp1.sh
    paste tmp.sh tmp1.sh  | sed "s/^/mv \"/" | sed "s/	/\" /"  > tmp2.sh
    sh ./tmp2.sh  
done


echo "Removing spaces from file names"
find . -type f -print | grep " "  | grep -v "\\$" > tmp.sh
sed "s/'//g" tmp.sh | sed "s/ /_/g" | sed "s/^\.\///" | sed "s/\&/_/g" > tmp1.sh
paste tmp.sh tmp1.sh  | sed "s/^/mv \"/" | sed "s/	/\" /"  > tmp2.sh
sh ./tmp2.sh