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

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to rename the extension of a file?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 03-26-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 7 February 2014, 8:50 AM EST
Location: Chennai
Posts: 560
Thanks: 41
Thanked 72 Times in 70 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 03-26-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 19 April 2014, 11:39 AM EDT
Location: India
Posts: 1,798
Thanks: 23
Thanked 516 Times in 495 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:40 PM.