[SWLUG] Find And Replace.

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


IFS=$'\n', in fact.  This works:

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


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