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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-05-2008, 07:15 PM
|
#1
|
|
QmailToaster Developer
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220
Rep:
|
Convert filename extension to lowercase
I'm whipping up a script to convert my VOB movies to avi for me, and I want to convert the filename's extension to lowercase (if it isn't already). I'm currently grabbing just the movie's name and stripping off the extension using this:
Code:
name=$1
newmovie="${name%.vob}"
so I can convert the movies to {movie}.avi for the filename.
I have a bunch of VOB files already, but not all of them have .vob instead of .VOB. I don't want to change the case of the movie's name, just it's extension.
My script only takes 1 movie as the input, is that helps any.
Anyone have any tips to push me in the right direction?
Thanks.
|
|
|
|
12-05-2008, 07:52 PM
|
#2
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
if all you need to do is just change VOB to vob
Code:
for f in *.VOB; do mv "$f" ${f/VOB/vob}; done
|
|
|
|
12-05-2008, 07:58 PM
|
#3
|
|
Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep: 
|
Here's a thought
#!/bin/sh
test=test.VOB
test1=$(echo $test | tr -d ".VOB")
test2=$(echo $test1 | tr -d ".vob")
echo $test2
test=test.vob
test1=$(echo $test | tr -d ".VOB")
test2=$(echo $test1 | tr -d ".vob")
echo $test2
Edit - I prefer the previous post
|
|
|
|
12-06-2008, 07:42 AM
|
#4
|
|
QmailToaster Developer
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220
Original Poster
Rep:
|
Thanks for the tips guys. I ended up going with this:
Code:
name=$1
ext=${name#*.}
if [ "$ext" != "vob" ]
then
if [ "$ext" != "VOB" ]
then
echo "Not a VOB movie!"
exit 1
fi
convertname="${name%.VOB}"
echo "Changing file extention to lowercase"
mv "$name" "$convertname".vob
fi
|
|
|
|
12-06-2008, 02:11 PM
|
#5
|
|
Member
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417
Rep:
|
Take in mind
will not work for a file name such as 'file.ok.vob'. You will need
Cheers
|
|
|
|
12-06-2008, 02:42 PM
|
#6
|
|
Member
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212
Rep:
|
Or:
If rename is available:
Code:
rename 's/VOB$/vob/' *.VOB
With Perl:
Code:
perl -e'
map { $o=$_; s/[^.]+$/\L$&/; rename $o, $_ }
glob "*.VOB"
'
With zsh:
Code:
autoload -U zmv
zmv -W '*.VOB' '*.vob'
|
|
|
|
12-07-2008, 06:24 AM
|
#7
|
|
QmailToaster Developer
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220
Original Poster
Rep:
|
Quote:
Originally Posted by jcookeman
Take in mind
will not work for a file name such as 'file.ok.vob'. You will need
Cheers
|
Thanks for the tip. I don't have any filenames like this now, but I'll make the change just in case for the future.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:02 PM.
|
|
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
|
|