Hi, Hope someone can help me with this... I've got a directory with about 1000 or so files named with this convention: filename.SNG.txt (don't ask - long story...) Now, filename is a random sequence of between 5 and eight numeric characters. My question is this: Does anyone know of a way in bash script to rename all the files of the above format to filename.txt? To throw (potentially) a spanner in the works, the files that need to be renamed aren't the only files in the directory. Any help will be gratefully accepted. James -- James Ogley, Webmaster, Rubber Turnip james@rubberturnip.org.uk http://www.rubberturnip.org.uk Jabber: riggwelter@myjabber.net Using Free Software since 1994, running GNU/Linux (SuSE 8.2). GNOME updates for SuSE: http://www.usr-local-bin.org
On Tue, 2003-06-17 at 23:48, James Ogley wrote:
I've got a directory with about 1000 or so files named with this convention:
filename.SNG.txt <snip> Does anyone know of a way in bash script to rename all the files of the above format to filename.txt?
mmv \*.SNG.txt \#1.txt mmv.rpm is somewhere on the CDs
mmv \*.SNG.txt \#1.txt mmv.rpm is somewhere on the CDs
Thanks for that... Problem is that I kind of need a generic bash solution, the system that I need to do this on is an unnetworked Windows box [that I do not own, before anyone thinks I've gone over to the Dark Side ;-)] with CygWin installed, and CygWin doesn't include mmv. (Although mmv is now committed to the memory banks for future reference). James -- James Ogley, Webmaster, Rubber Turnip james@rubberturnip.org.uk http://www.rubberturnip.org.uk Jabber: riggwelter@myjabber.net Using Free Software since 1994, running GNU/Linux (SuSE 8.2). GNOME updates for SuSE: http://www.usr-local-bin.org
* James Ogley (james@usr-local-bin.org) [030617 14:48]:
filename.SNG.txt
(don't ask - long story...)
Now, filename is a random sequence of between 5 and eight numeric characters.
My question is this:
Does anyone know of a way in bash script to rename all the files of the above format to filename.txt?
Something like ls *SNG* | while read name; do new=${name/.SNG.txt/.txt} mv $name $new done -- -ckm
On Tue, 2003-06-17 at 22:48, James Ogley wrote:
Hi,
Evening,
Hope someone can help me with this...
Will give it a try. :)
I've got a directory with about 1000 or so files named with this convention:
filename.SNG.txt
(don't ask - long story...)
Now, filename is a random sequence of between 5 and eight numeric characters.
But it _always_ follows the convention of <something>.SNG.txt ?
My question is this:
Does anyone know of a way in bash script to rename all the files of the above format to filename.txt?
Easy. for file in *.SNG.txt do newfile=${file%%.*} mv $file $newfile.txt done
To throw (potentially) a spanner in the works, the files that need to be renamed aren't the only files in the directory.
As long as no files you want to keep as they are are called <something>.SNG.txt you should be alright.
Any help will be gratefully accepted.
Hope this helped.
--
Anders Karlsson
James Ogley wrote:
Hi,
Hope someone can help me with this...
I've got a directory with about 1000 or so files named with this convention:
filename.SNG.txt
(don't ask - long story...)
Now, filename is a random sequence of between 5 and eight numeric characters.
My question is this:
Does anyone know of a way in bash script to rename all the files of the above format to filename.txt?
To throw (potentially) a spanner in the works, the files that need to be renamed aren't the only files in the directory.
Any help will be gratefully accepted.
Just another option: for f in *SNG.txt; do mv $f `basename $f .SNG.txt`.txt done; these are backticks. and yes, it is quite ineffective for many files as for every file basename needs to be called. -- Rouvas Stathis rouvas@di.uoa.gr http://www.di.uoa.gr/~rouvas
participants (5)
-
Anders Johansson
-
Anders Karlsson
-
Christopher Mahmood
-
James Ogley
-
Rouvas Stathis