ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If no command name results, the variable assignments affect the current shell environment. Otherwise, the variables are added to the environment of the executed command and do not affect the current shell environment.
Thanks for explaining inc. link and sorry for not appreciating your use of it at http://www.linuxquestions.org/questi...24#post3609924. Vague memories of reading about it are coming to mind along with deciding not to use it because it did not match legibility aspirations. All the same it's a valid technique and I should know about it, even if I choose not to use it.
Just for fun (and the upcoming obfuscated bash competition):
BTW, Files I want to rename are scattered across different folders. for instance, they are all in different subfolders. How can I move them one directory up in order to rename them in batch?
Sorry ntubski, I have given you the wrong info. There should be no dot between the numerals and the song names.
01-01 song with spaces in filename.mp3
01-02 song with spaces in filename.mp3
etc...
I have changed the script to (ls *-*\ *.mp3),but it didn't work.
Can you explain how does your "cut -d. -f2" work?
"cut -d. -f2" assumes that the song name is separated from the numerals by dots, so of course it doesn't work. It extracts the text between the 1st and 2nd dots.
Here's a version that assumes the song name is the part that comes after the numbers and dashes. I had to rearrange the loop a bit to handle whitespace.
Code:
~/tmp/songs$ while read -d$'\n' song ; do
> echo *"$song" TO "$song" ; done < <(ls *.mp3 | sed 's/^[-0-9]* //' | sort -u)
01-01 a song.mp3 01-02 a song.mp3 TO a song.mp3
01-01 another song.mp3 01-02 another song.mp3 TO another song.mp3
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.