LinuxQuestions.org
Visit Jeremy's Blog.
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 12-05-2008, 07:15 PM   #1
jakev383
QmailToaster Developer
 
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220

Rep: Reputation: 31
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.
 
Old 12-05-2008, 07:52 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
if all you need to do is just change VOB to vob
Code:
for f in *.VOB; do mv "$f" ${f/VOB/vob}; done
 
Old 12-05-2008, 07:58 PM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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
 
Old 12-06-2008, 07:42 AM   #4
jakev383
QmailToaster Developer
 
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220

Original Poster
Rep: Reputation: 31
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
 
Old 12-06-2008, 02:11 PM   #5
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
Take in mind
Code:
ext=${name#*.}
will not work for a file name such as 'file.ok.vob'. You will need
Code:
ext=${name##*.}
Cheers
 
Old 12-06-2008, 02:42 PM   #6
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
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'
 
Old 12-07-2008, 06:24 AM   #7
jakev383
QmailToaster Developer
 
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by jcookeman View Post
Take in mind
Code:
ext=${name#*.}
will not work for a file name such as 'file.ok.vob'. You will need
Code:
ext=${name##*.}
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.
 
  


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
Convert static library (Filename.a) to dynamic shared object (filename.so) afx2029 Linux - Software 4 08-17-2007 06:07 AM
How to get filename extension makowka Programming 7 04-30-2007 05:32 PM
rm: cannot remove 'filename.extension' Operation not permitted shinystuffrox Linux - Software 8 03-07-2007 05:09 AM
redirect to same filename without extension geekpie Linux - Software 1 10-31-2006 10:12 AM
Filename extension question BajaNick Linux - General 2 07-05-2004 05:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:18 AM.

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
Open Source Consulting | Domain Registration