m4a->mp3 help

Jonas Norlander jonorland at gmail.com
Mon Oct 13 10:30:41 BST 2008


2008/10/12 Nils Kassube <kassube at gmx.net>:
> Jonas Norlander wrote:
>> 2008/10/12 Nils Kassube <kassube at gmx.net>:
>> > You could try this:
>> >
>> > find ~/Music -iname "*.m4a" | while read fn;do
>> > lame -V0 -h -b 160 --vbr-new "$fn" "${fn%[mM]4[aA]}mp3";done
>>
>> Intresting. Do you mind explain the "${fn%[mM]4[aA]}mp3" part? I
>> understand that it will replace m4a with mp3 but i don't understand
>> how.
>
> The bash syntax ${fn%m4a} would result in the environment variable $fn
> with m4a cut off from the end of the string. However this would only work
> if the m4a part is lower case only. However the find option -iname would
> also find files with upper case file names. Therefore I used "[mM]"
> instead of "m" alone and "[aA]" instead of "a" alone as wildcards because
> it will work for both upper and lower case. Finally I want to add "mp3"
> to the end of the string which results in "${fn%[mM]4[aA]}mp3" and the
> quotes are added just in case there are spaces within the original file
> name. If that explanation wasn't good enough, feel free to ask again.
>

Thanks!

So in short ${fn%m4a} would match and remove m4a from the end of the
string and ${fn#m4a} would from the beginning of the string? But what
about the %% and ## syntax?

>> It should be possible with some sed script  to.
>
> Well, if you speak sed that is certainly possible but that would
> unnecessarily start sed for every filename :)
>

True that would be unnecessarily.

/ Jonas



More information about the kubuntu-users mailing list