[PLUG] Mass Removal of White Space in File Names

Fred James fredjame at fredjame.cnc.net
Mon Apr 18 01:27:42 UTC 2011


Rich Shepard 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.
>
>    Suggestions appreciated.
>
> Rich
>   
Rich Shepard
Not sure why the need for a "one-liner"?  This bit of script (SH/BASH) 
extracts a list of files (excluding directories).  From there my 
approach would be to either ...
    feed it to AWK
    make a file of it and use EX (within VI) to create the desired 
command lines
... I'd probably use AWK, though.

Keep in mind that it would be a good idea to check for duplicate results 
before actually committing to this ... could be disastrous.
Good luck
Regards
Fred James

#! /bin/bash
#       Ren.sh
#
BaseDir="/whatever/"

for file in `ls $BaseDir`
do
        if test ! -d "$BaseDir$file"
        then
                echo "\"$file\""
        fi
done
exit 0




More information about the PLUG mailing list