LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



Reply
 
Search this Thread
Old 07-18-2009, 04:24 PM   #31
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878

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.
 
Old 07-19-2009, 07:47 AM   #32
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by ntubski View Post
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
 
Old 07-22-2009, 03:29 AM   #33
Qu3ry
LQ Newbie
 
Registered: Jul 2009
Distribution: ubuntu, fedora, OpenSolaris
Posts: 21

Original Poster
Rep: Reputation: 15
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 03:54 AM.
 
Old 07-22-2009, 03:37 AM   #34
Qu3ry
LQ Newbie
 
Registered: Jul 2009
Distribution: ubuntu, fedora, OpenSolaris
Posts: 21

Original Poster
Rep: Reputation: 15
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 10:58 AM.
 
Old 07-22-2009, 07:59 PM   #35
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878
Quote:
Originally Posted by Qu3ry View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 8 12-18-2013 06:36 PM
Trouble with making a bash script to read in different files and rename output files. rystke Linux - Software 1 05-07-2009 09:00 AM
list files NOT matching a pattern smart_sagittari Linux - Newbie 9 05-20-2005 06:32 AM
awk cli to rename a list of files... pld Linux - General 4 02-15-2005 11:57 PM
Is it possible to rename an Ezmlm maling list? tomdkat Linux - Software 0 02-02-2005 05:00 PM


All times are GMT -5. The time now is 05:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration