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....

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

With a modern shell:

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