Sharon Kimble grabbed a keyboard and wrote: > Thanks Dave, this is what I have - > #!/bin/bash > for in in *.mp3 > do > out=`echo $in|cut -d_ -f 1-15 -` > mv $in $out.mp3 > done > > and I've run it three times on the directory, and here is some of the > outcomes - > 4_Extra_at_Bletchley_Park_-_4_Extra_at_Bletchley_Park_b03g8lxl_default.mp3.mp3.mp3 > 15_Minute_Drama_-_AM_Homes_-_This_Book_Will_Save_Your_Life_Episode_2.mp3.mp3 > 15_Minute_Drama_-_The_Pillow_Book_Time_and_Change_Episode_1_b03brkss_default.mp3.mp3.mp3 > > So as you see it works sometimes, but its also adding an extra mp3 to > the end of the line each time the script is run, which isn't ideal! > > I've been having a look through all of the mp3 files and they all seem > to be _b0, so that is a constant ..... _b0******_default.mp3 > > But, there are some files, only a very few, in this syntax - > Witness_-_The_Death_of_Chinese_Cockle_Pickers_p01qpr03_default.mp3.mp3.mp3 > with _p0 starting off the weird file names. Well, like I said - the script I whipped up depends on a fixed number of fields (words separated by "_") being present in the filename. If any of them are different, then it's going to give you the weird behavior that you're seeing here. I'd suggest going with Mark's sed solution - since it's not counting fields before getting to the part that you want to get rid of, I suspect it will work better for you. :-) --Dave
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature