[PLUG] Mass Removal of White Space in File Names
Fred James
fredjame at fredjame.cnc.net
Mon Apr 18 14:09:40 UTC 2011
Fred James wrote:
> 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
Offering this revised script that will produce a file containing lines
like ...
mv "my friend and I" myfriendandI
... this file can then be executed as a script by appending the 'sh '
... OK?
Regards
Fred James
> ls $ThisDir | grep -v $FileName0 > $FileName0
> while read Name
> do
> if test ! -d "$Name"
> then
> x=`echo "$Name" | awk '{print (index($0, " "))}'`
> if test $x -gt 0
> then
> NewName=`echo "$Name" | sed -e 's/ //g'`
> echo "mv \"$Name\" $NewName" > $FileName1
> fi
> fi
> done < $FileName0
More information about the PLUG
mailing list