[SWLUG] Find And Replace.

David Scourfield david.scourfield at llynfi.co.uk
Thu Jan 7 15:57:48 UTC 2010


After fiddling (I can never resist a coding task, however trivial) I've 
tested this, which works on subdirectory entries too:

#!/bin/bash
IFS=$'\n'
for i in $( find -type f -name \*.mp3 );
do
    src=$i
    tgt=$(echo $i | sed -e "s/-/ - /")
    mv $src $tgt
done

Dai

Huw Lynes wrote:
> On Thu, 2010-01-07 at 14:57 +0000, Andrew Jenkins wrote:
>   
>> Marcus.Davage at googlemail.com wrote:
>>     
>>> Try "s/-/\ -\ /"
>>> (escape characters before the spaces.
>>> M
>>>       
>> Ah, I was just trying that before your post. No, sorry
>> exactly the same result as before (Amazing.mp3 is
>> not a directory etc.)
>>     
>
> I think the script is splitting filenames on spaces. You need
>
> $IFS='\n'
>
> to tell Bash to only split on newlines. Put that somewhere at the top of
> the script.
>
> Thanks,
> Huw
>
>   



More information about the Swlug mailing list