On Sun, Apr 17, 2011 at 4:44 PM, Rich Shepard <[email protected]> wrote: > I have two directories of images where each file name has spaces between > the words. I'm not having success writing a shell script that takes each > name in sequence, removes the white spaces, and leaves the extension as-is. > I'm certain that this can be done in perl, python, ruby, scheme, awk, sed, > and so on. I believe that a shell script would be a one-liner.
There is as perl script called 'rename' that makes this very easy: $ rename 's/ //g' Some\ File\ Name.ext Will take the spaces out (destructively, so be careful. I don't know how it handles filename conflicts that may arise, I suspect not gracefully.). Combined with find and xargs, you can apply it to a whole directory tree (I haven't tested the following line though, so beware of typos/etc..): $ find <path> -type f | xargs rename 's/ //g' On debian my debian system, 'rename' is a symlink to /etc/alternatives/rename, which points to /usr/bin/prename, which apt-file says came with perl. If you don't have 'rename', try 'prename'. There are also probably other programs called rename. This is what I get if I run 'rename' with no arguments: $ rename Usage: rename [-v] [-n] [-f] perlexpr [filenames] --Rogan > > Suggestions appreciated. > > Rich > _______________________________________________ > PLUG mailing list > [email protected] > http://lists.pdxlinux.org/mailman/listinfo/plug > _______________________________________________ PLUG mailing list [email protected] http://lists.pdxlinux.org/mailman/listinfo/plug
