[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Losing '_b00jdlb8_default' from a files name?



Sharon Kimble grabbed a keyboard and wrote:
> I am using this script to convert radio programmes downloaded with
> 'get-iplayer' from '*.m4a' to '*.mp3', and it works very well. 
> 
> for i in *.m4a;
> 			do faad "$i"
> 				x=`echo "$i"|sed -e 's/.m4a/.wav/'`
> 				y=`echo "$i"|sed -e 's/.m4a/.mp3/'`
> 				lame -h -b 192 "$x" "$y"
> 				rm -f "$x"
> 			done;
> 
> But, there is a problem. They come in this format -
> '15_Minute_Drama_-_AM_Homes_-_This_Book_Will_Save_Your_Life_Episode_5_b00jdlb8_default.m4a'
> 	
> How can I lose the '_b00jdlb8_default' section please? It is always
> in this format but with different letters and numbers in the section
> before 'default'. 
> 
> I have quite a few programmes already converted so I also need to be
> able to use this ability on them too. I would welcome another script
> that could perform this please?

I went for the quick and dirty, assuming that the filenames would always
be structured as your above example.  Whipped this script up (name the
file whatever you want), and tested it:


#!/bin/bash
for in in *.m4a
do
  out=`echo $in|cut -d_ -f 1-15 -`
  mv $in $out.m4a
done


The -d_ sets "_" as a delimiter between fields, and the "-f 1-15" tells
it I want to keep fields 1-15 and throw the rest away (since the
filename goes 15 fields before running into the part that you want to be
rid of).  Then it does a simple mv command to change the filename,
appending the .m4a back to the end of the destination filename.

There's probably a better way of doing this, one that doesn't depend on
a fixed number of fields, but I haven't had time to research it as of
yet. :-)

               --Dave


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Reply to: