LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 03-07-2008, 01:54 AM   #1
linux_teller
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
renaming directories from upper case to lower case, help!!


Hello Linux Gurus,
I am pretty new to linux but have lot of passion to learn, I stumbledupon a script from a website and I couldn't possibly understand the hilighlighted peice of code. I really appreciate if you could help me understand this syntax.

having trouble with the following code
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`

The complete code

for f in *; do
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
mv "$f" "$g"
done

This code was found in the following url
webxadmin.free.fr/article/shell-rename-all-files-in-subdirectories-to-lowe-135.php
 
Old 03-07-2008, 03:03 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 239Reputation: 239Reputation: 239
Code:
# a=string
# echo $a | awk '{print toupper($0)}'
STRING
 
Old 03-07-2008, 03:15 AM   #3
linux_teller
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks but I want to understand the higlighted code.

Quote:
Originally Posted by ghostdog74 View Post
Code:
# a=string
# echo $a | awk '{print toupper($0)}'
STRING
Hi, I really appreciate your awk command reference, but I want to understand the command highlighted in red from my original post.

g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`


I appreciate gurus help here.

Thanks
teller
 
Old 03-07-2008, 05:15 AM   #4
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
Actually I'm not getting any difference whether or not I put the 'xxx' part is there in the expr section.
I made these 3 files: F ILE1 FIL -E2 fIlE3
Now I run the script given in that link (last line is replaced with echo instead of mv):
Code:
bash-2.05b ~/scrap$ for f in *; do
> g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
> echo $g
> done
f ile1
fil -e2
file3
And now if I remove the 3 x's in line 2:
Code:
bash-2.05b ~/scrap$  for f in *; do
> g=`expr "$f" : '\(.*\)' | tr '[A-Z]' '[a-z]'`
> echo $g
> done
f ile1
fil -e2
file3
Its the same! This link gives the same example and seems to imply that this usage of expr can handle control characters and whitespace better than simpler scripts. I'm guessing that's what the xxx is for. Apart from that the explanation is fairly simple I guess.
Code:
g=`expr "$f" : '\(.*\)' | tr '[A-Z]' '[a-z]'`
expr "$f" : '\(.*\)' This part saves the entire value of $f. Usual regex stuff here.
| tr '[A-Z]' '[a-z]'... and passes it to the tr commands which changes the case.
So maybe someone else here knows how prefixing 'xxx' in the regex helps.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Upper and lower case problem when mount hardisk UltraSoul Linux - Newbie 1 10-28-2005 08:50 AM
grep [A-Z] & [a-z] match both upper and lower case. jschiwal Linux - General 4 05-28-2005 06:43 AM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 04:09 PM
Lower case to upper case letter sudhasmyle Programming 1 12-03-2004 04:15 AM
Apache and upper or lower case. dsiguy Linux - General 3 02-04-2003 11:02 AM


All times are GMT -5. The time now is 07:15 PM.

Main Menu
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