View Single Post
  #4   (View Single Post)  
Old 17th June 2013
thomasw_ thomasw_ is offline
Real Name: thomas
Port Guard
 
Join Date: Feb 2013
Location: kimberley
Posts: 30
Default

Handy solutions here, and being a fan of the simplicity of substitution in sed, I am especially fond of this last example by Mike.

Some folks, though, might want to insert a "_ "or a " ." where spaces occur, especially in filenames. I wrote a simple script that recursively removes spaces in a directory and in the names of its files. I find it useful for renaming my audio files.

I'll paste it below for anyone to use or modify if anyone finds it useful.

Code:
 rmspaces.sh

#!/bin/ksh
#recursive script to replace spaces in filenames with periods


find . -name '* *' | while read file;
do
target=`echo "$file" | sed 's/ /\./g'`;
echo "Renaming '$file' to '$target'";
mv "$file" "$target";
done;
Reply With Quote