Sed wizard wanted to write oneliner
I downloaded the Complete Buddy Holly by Purple Chick.
Unfortunately there are 10 directories with embedded blanks in the name (disc 1, ..., disc 10). & the 40 or so files in each directory are named Track 01.flac, Track 02.flac, etc which is pretty useless when you want to play the songs. I want to have a bash script to rename the flac files using a file containing titles of the songs disc by disc. My input title file is formatted like this (I used gedit to remove embedded spaces). 01:_Little_Baby 02:_(You're_So_Square)_Baby_I_Don't_Care 99:_Long_Complicated_Title(Perhaps_With_Special_Characters) What I want as output for my bash script file is mv Track\ 01.flac 01_Little_Baby.flac mv Track\ 02.flac 02_(You're_So_Square)_Baby_I_Don't_Care.flac mv Track\ 99.flac 99_Long_Complicated_Title(Perhaps_With_Special_Characters).flac or better still echo "mv Track\ 01.flac 01_Little_Baby.flac" echo "mv Track\ 02.flac 02_(You're_So_Square)_Baby_I_Don't_Care.flac" echo "mv Track\ 99.flac 99_Long_Complicated_Title(Perhaps_With_Special_Characters).flac" so I can check it all works before running the script. So far my bash script goes from directory to directory. What I need now is a script wizard to write a sed oneliner that changes the title file so that I can insert the mv lines in the bash script. Titles may contain brackets, apostrophes, question marks, maybe even exclamation marks. Do they need a backslash added to prevent interpretation as metacharacters by bash (or sed) ? How to duplicate the track number so it can make both the arguments for mv ? Thanks to anyone who can crack this in a minute instead of me finding out by reading Bruce Barnett's sed doc for hours. |
Quote:
There are important questions that you haven't answered: 1. How is the track title file indexed to correspond to the .flac files? Is it by number, as in your example, or by line, or both? 2. How is the title file set up to correspond to the individual music directories? Is there a different title file for each directory, or is there a master title file? 3. Do the directory names correspond to album names, or are they arbitrary and uninformative? Without more information, I can give you the barest outline of what you are after: Code:
path="/path/of/interest" |
If I understand the OP correctly he's after something like this; since
the spec isn't very clear I've assumed for simplicities sake that the list of desired names is in the same directory that has the flacs. Code:
#!/bin/bash maybe with find as suggested above, to iterate over the whole structure with undesirable file-names. Cheers, Tink P.S.: sed would have worked just fine, but cut is smaller/quicker in this particular case. |
lutusp & tinkster - Apologies for my inadequate spec. I'll try to be clearer in future.
There is just one file for the titles. It contains 10 lists each with the format described in numerical order with one title per line. At the head of each list I have inserted "cd /path of directory for relevant list" & some comment lines. The album/directory names are just "disc 1", ..., "disc 10". lutusp: I understand your script - I'm sure it will come in handy here (added to Tinkster's) & in future. Tinkster : My Linux Phrasebook doesn't even list cut in the index so I don't understand your solution yet, but I will in a few minutes. Maybe you can suggest a better book for me. |
Quote:
Also, the program will need to be written in Perl or Ruby -- this is beyond a reasonable bash script. The reason is that the master file's contents would need to be unambiguously partitioned dynamically as the directories were scanned, to access the right ten song titles for each directory. Good luck! |
I second the motion regarding the file-structure.
I don't know about the need for perl or ruby, I'm sure awk could go a long way with this. Cheers, Tink P.S.: As for the OPs question regarding reading material; there's tons out there, and I haven't read any. I often recommend scripting tutorial websites. There's one book I do encourage people to buy, and that's because of its quirky structure. It's full of cross-references, and encourages the inquisitive mind to follow along. O'Reilly "Unix Power Tools" (*not* the Linux version, it's quite lame by comparison). |
Directory structure is really simple.
/home/me/Desktop/The_Complete_Buddy_Holly is the main path & then inside that there are disc 1, disc 2, ..., disc 10 containing target files & a couple of other directories for album covers & brochures. I think bash is up to that if the script file is correctly generated by a find. Or I can split the title file into 10. Tink - I'd been browsing Unix Power Tools on Amazon but was also wondering whether to wait for new edition of Mark Sobell's book A Practical Guide to Linux(R) Commands, Editors, and Shell Programming which is due out in December. BTW Your location tag gave me a belly laugh. |
Heh ... glad you got a good laugh out of it.
I'll look up the book you're asking about in my copious spare time ;} and come back with my views on if (if I can find it somewhere around, that is). Can you post a representative section of your control file, something to work on? Cheers, Tink |
All times are GMT -5. The time now is 03:35 AM. |