Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
|
07-18-2009, 03:24 PM
|
#31
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,793
|
There is no subshell, assignments before a command are only in effect for that command.
Simple-Command-Expansion:
Quote:
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.
|
I used this trick in the extracting floating numbers from variable using bash's builtin string chopping thread.
|
|
|
07-19-2009, 06:47 AM
|
#32
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by ntubski
|
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):
|
|
|
07-22-2009, 02:29 AM
|
#33
|
LQ Newbie
Registered: Jul 2009
Distribution: ubuntu, fedora, OpenSolaris
Posts: 21
Original Poster
Rep:
|
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?
Last edited by Qu3ry; 07-22-2009 at 02:54 AM.
|
|
|
07-22-2009, 02:37 AM
|
#34
|
LQ Newbie
Registered: Jul 2009
Distribution: ubuntu, fedora, OpenSolaris
Posts: 21
Original Poster
Rep:
|
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?
Quote:
$ find Quantum/ -type f
Quantum/Disc 1/.directory
Quantum/Disc 1/01.avi
Quantum/Disc 1/02.avi
Quantum/Disc 1/03.avi
Quantum/Disc 1/04.avi
Quantum/Disc 1/05.avi
Quantum/Disc 1/06.avi
Quantum/Disc 2/.directory
Quantum/Disc 2/07.avi
Quantum/Disc 2/08.avi
Quantum/Disc 2/09.avi
Quantum/Disc 2/10.avi
Quantum/Disc 2/11.avi
Quantum/Disc 2/12.avi
Quantum/Disc 3/.directory
Quantum/Disc 3/13.avi
|
etc
EDIT: I have figured it out:
in working directory, type
Quote:
#find . -type f -exec mv {} . \;
|
Last edited by Qu3ry; 07-22-2009 at 09:58 AM.
|
|
|
07-22-2009, 06:59 PM
|
#35
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,793
|
Quote:
Originally Posted by Qu3ry
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
|
|
|
All times are GMT -5. The time now is 09:26 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|