LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-26-2009, 10:41 PM   #1
cashinke
LQ Newbie
 
Registered: Aug 2009
Posts: 1

Rep: Reputation: 0
rename multiple file by moving part of the name to end of extension


Hi there,
How do you rename:

abc123.txt
abc124.txt
abc125.txt

to

abc.txt.123
abc.txt.124
abc.txt.125

Basically, I want to move the digits from the filename to after the extension.

It works for one file if I type:
rename 123.txt .txt.123 abc.txt.123

but I have thousands of files like these.

Thank a bunch

Last edited by cashinke; 08-26-2009 at 10:45 PM. Reason: forgot to insert what i've tried
 
Old 08-26-2009, 11:55 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!

... try on few copies in a tmp directory first ;}

Code:
for i in *
do
  target=$( echo $i | sed -r 's/([^0-9]*)([0-9]+)\.txt/\1.txt.\2/')
  mv $i $target
done

Cheers,
Tink

Last edited by Tinkster; 08-27-2009 at 12:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rename multiple files with random extension ltodd2 Linux - General 12 03-25-2009 07:56 AM
Multiple File Rename maker10 Linux - Newbie 7 11-06-2007 10:32 AM
LXer: Rename multiple files to another extension in Linux LXer Syndicated Linux News 0 08-19-2007 04:10 PM
How to rename multiple files with the same extension rogueeve Linux - Newbie 3 05-18-2007 02:54 AM
Multiple File Rename windisch Linux - General 11 11-10-2005 01:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration