LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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
  Search this Thread
Old 06-24-2009, 04:27 AM   #1
umesh_linuxq
LQ Newbie
 
Registered: Jun 2009
Posts: 8

Rep: Reputation: 0
change file extension


Hi

How can we change the file extensions from Linux shell scripts, and also from Perl script ?

Regards
Umesh.K
 
Old 06-24-2009, 04:34 AM   #2
rikxik
Member
 
Registered: Dec 2007
Posts: 88

Rep: Reputation: 19
you can use "mv" to rename files in shell scripts and "rename" in perl scripts.
 
Old 06-24-2009, 05:11 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
I find the easiest way to change file extensions in shell scripts is through the use of parameter substitution of variables. Consider the following:
Code:
$ somevar=filename.ext
$ echo ${somevar}
filename.ext
$ echo ${somevar%.ext}
filename
$ echo ${somevar%.*}
filename
$ newvar=somefile.someotherext
$ echo ${newvar%.*}
somefile
$ yetanothervar=somefile.padding.ext
$ echo ${yetanothervar%.*}
somefile.padding
See http://tldp.org/LDP/abs/html/paramet...stitution.html for a more elegant and in depth explanation.
 
  


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
Linux file extension vs Dos file Extension? manaa Linux - Newbie 6 02-12-2009 04:19 PM
bash: renaming file extension based on actual file type alekone Linux - General 9 12-28-2008 09:12 AM
How to know the file extension with C geek_man Programming 4 11-26-2007 09:33 PM
what is this file extension Arkan123 Linux - Newbie 5 01-14-2006 08:07 AM
why when redirecting output to a file any file extension seems to be fine? dr_zayus69 Linux - General 1 05-21-2005 04:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration