[PLUG] Re: script to rename files?

Jon LeVitre jonlevitre at yahoo.com
Sat Apr 9 14:31:25 UTC 2005


Last time I did something like this, the for loop didn't parse it
correctly (it treated each word as a separate token).

This should work:
 ls "* *" | while read i
 do
  j=$(echo $i|sed 's# ##g'); mv -vi "$i" $j
 done

Jon

Wil Cooley wrote:
> On Fri, 2005-04-08 at 20:40 -0700, Michael D. Harris wrote:
> > Since I do not have enough experience with scripts in bash,
> > can someone give me a script to read file names in, remove
> > spaces, and save the file without the spaces.  Preferable
> > removing the original file?
> > 
> > Thanks, just to complicated for me to do yet,
> 
> Some people will point you as 'rename(1)', but I always find
> it too much trouble to learn a new command when a little
> scripting works just as well:
>
> for i in *; do j=$(echo $i|sed 's# ##g'); mv -vi "$i" $j; done
>
> Oh yes you can probably be fancy and use some bash
> parameter expansion; a little more obscure perhaps, but
> cleaner looking:
>
> for i in *; do mv -vi "$i" ${i// /}; done


		
__________________________________ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 



More information about the PLUG mailing list