How to rename the extension of a file? | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

How to rename the extension of a file?

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-26-2013
rahulkt1987 rahulkt1987 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 26 March 2013, 5:41 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How to rename the extension of a file?

Hello,
I have multiple files named rscclog_2013-03-25.txt;3 in a directory, where 2013-03-25 is the previous day's date and the number after extension .txt preceded by a ';' is any number which i do not know beforehand.

Now, i have to rename all such files as rscclog_2013-03-25.txt
thus, removing the ';3' after the extension.

Any help will be appreciated....
Sponsored Links
    #2  
Old Unix and Linux 03-26-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 26 November 2014, 5:10 AM EST
Location: Chennai
Posts: 567
Thanks: 43
Thanked 74 Times in 72 Posts

Code:
file_name="rscclog_2013-03-25.txt;3"
mv $file_name $(echo $file_name | sed 's/;[0-9]*//g')

Sponsored Links
    #3  
Old Unix and Linux 03-26-2013
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 31 March 2015, 1:32 AM EDT
Location: India
Posts: 1,872
Thanks: 27
Thanked 537 Times in 514 Posts
With a modern shell:

Code:
file_name="rscclog_2013-03-25.txt;3"
mv $file_name ${file_name%;*}

The Following User Says Thank You to balajesuri For This Useful Post:
PikK45 (03-26-2013)
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rename file extension. pinnacle Shell Programming and Scripting 4 03-02-2013 07:01 AM
Rename file to uppercase except extension johninweb Shell Programming and Scripting 4 03-15-2012 04:40 AM
rename a file with new extension apple2685 Shell Programming and Scripting 1 05-20-2011 01:55 AM
rename file extension sriram003 Shell Programming and Scripting 4 09-08-2008 02:28 AM
Recursicely search and rename file extension riverside Shell Programming and Scripting 7 04-11-2008 10:02 AM



All times are GMT -4. The time now is 06:32 PM.