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: 1 September 2015, 11:00 AM EDT
Location: Chennai
Posts: 573
Thanks: 50
Thanked 75 Times in 73 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: 23 August 2015, 9:36 AM EDT
Location: India
Posts: 1,892
Thanks: 27
Thanked 539 Times in 516 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

Linux 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 12:09 PM.