Organizing music files alphabetically but skipping the "The_" in artist names
Hey everyone!
I'm totally new to linux but I decided to give it a go full time now. I'm using Ubuntu 12.04 and I have been trying to learn to use the shell. So far everything is making sense but this one thing. Just for practice and what-not I made a .txt file with a long list format of my music directory and I was wondering how I could go about sorting all of the artists alphabetically while ignoring the "The_" in the beginning of many artist's names. You know, putting "The_Beatles" up by "Billy_Joel" instead of next to "Three_Doors_Down". I have been experimenting with wildcards associated with ls but that doesn't seem to be the answer. I have really just been toying with various incarnations of $ls -l > Music.txt Sorry if this seems like a really stupid question but any help is greatly appreciated! |
Hello a21210, welcome to LQ,
if I've understood your question correctly, you want to sort the files this way, but not rename? This should be possible with sed Code:
ls | sed 's/^the_//i' | sort BTW: its not a stupid question |
Hi and welcome to LinuxQuestions!
The sort command hasn't got any option to exclude a pattern from the sorting process. A workaround might be: Code:
sed '/^The_/{s/^The_//;s/$/@/}' file | sort | sed '/@/{s/^/The_/;s/@//}' |
YESSS! You guys rock! Ok, so I wanted to save this list as a text file for fun and I could NOT get it to work in just one line or with just one file so this is what I ended up using colucix's idea but just spread it out a bit. It worked like a champ and I learned a ton about using the sed command at the same time. Thanks again guys!
Code:
Music$ ls > music4.txt |
Try
Code:
ls | sed 's/^the_//i' | sort > mymusic.txt Code:
sed '/^The_/{s/^The_//;s/$/@/}' file | sort | sed '/@/{s/^/The_/;s/@//}' > mymusic.txt Code:
ls > file Edit: checked with my Music directories, it works |
In Perl or C you can define the (callback) comparison function to use in a sort and you could arrange for such a function to discard "The " at the start of a name.
See bug 5 - http://www.asktog.com/Bughouse/10Mos...esignBugs.html |
Quote:
Markus |
Quote:
|
Quote:
Markus |
Quote:
|
Well, in this case one had to insert $. But the idea behind the code is to use a character which is used only for this decoration. If I knew that @ would be in the filenames, I would chose another character, for example #. Consider what would happen if @ were in the end of the filename.
Markus |
I'd do it like this:
Code:
sed 's/\(^[Tt][Hh][Ee][-_ ]\)\(.*\)/\2\t\1\2/' input.list | sort -f | cut -f2 |
Quote:
|
All times are GMT -5. The time now is 09:26 AM. |