Register
It is currently Sun Sep 21, 2014 4:06 am

Title Case (Camel Case) File Names


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Tue Jul 21, 2009 6:07 pm   

Joined: Tue Jul 21, 2009 5:59 pm
Posts: 3
I would like help creating a script to rename files in title case. I use dots instead of spaces in my file names, so I'd like to turn this:

some.show.or.song.avi

into this:

Some.Show.Or.Song.avi

I'm sure there's a way to do it with awk, but I'm not that good with awk. I couldn't figure out how to do it with sed.

All suggestions are appreciated.


Top
 Profile  
 PostPosted: Wed Jul 22, 2009 12:48 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Hum, this was way easier then I thought :D
Code:
sajko@hanna:~> echo some.show.or.song.avi | sed -e "s/\([^\.]\+\)\./\u\1\./g"
Some.Show.Or.Song.avi


the trick is \u which tells regexp that the next character should be uppercase, this also applies for \l (but for lowercase).
Also \U and \L is available which makes the whole line in *-case

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Wed Jul 22, 2009 12:50 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Oh sry, a script it was yes... I'll give you a one liner :)
Code:
for i in /path/to/files/*; do mv "$i" "$(echo $i | sed -e "s/\([^\.]\+\)\./\u\1\./g")"; done


This will rename _all_ files in the directory (you can of course just run the mv and replace $i with the directory name)

Best Regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Fri Jul 24, 2009 8:37 pm   

Joined: Tue Jul 21, 2009 5:59 pm
Posts: 3
Not sure why, but it's not capitalizing the first letter of the file name. When I used the regex to rename text, it works fine.


Top
 Profile  
 PostPosted: Sat Jul 25, 2009 4:14 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
hum... wierd... this might work thou. The next regexp just capitalizes the first character in the text :)
Code:
echo some.show.or.song.avi | sed -e "s/\([^\.]\+\)\./\u\1\./g" -e "s/^\(.\)/\u\1/"


Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Sat Jul 25, 2009 11:52 am   

Joined: Tue Jul 21, 2009 5:59 pm
Posts: 3
tinivole helped me out over at Ubuntu Forums with a simple solution using the rename function:

Code:
rename 's/\b(\w+\.)/\u$1/g' ~/Desktop/sample_dir/*


It works very simply. Here's a link http://ubuntuforums.org/showthread.php?t=1222467 to my post and the replies.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP