LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Rename files matching a list (https://www.linuxquestions.org/questions/programming-9/rename-files-matching-a-list-739558/)

ntubski 07-18-2009 03:24 PM

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.

catkin 07-19-2009 06:47 AM

Quote:

Originally Posted by ntubski (Post 3612044)
There is no subshell, assignments before a command are only in effect for that command.

Simple-Command-Expansion

I used this trick in the extracting floating numbers from variable using bash's builtin string chopping thread.

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):
Code:

a=X b=Y c=Z env

Qu3ry 07-22-2009 02:29 AM

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?

Qu3ry 07-22-2009 02:37 AM

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 {} . \;

ntubski 07-22-2009 06:59 PM

Quote:

Originally Posted by Qu3ry (Post 3616077)
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 07:45 PM.