The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rename a lot of files again ajp7701 Shell Programming and Scripting 11 03-31-2008 04:36 PM
trying to rename the files in dir hankooknara Shell Programming and Scripting 8 07-02-2007 12:36 AM
rename many files fsmadi SUN Solaris 4 04-30-2007 08:27 AM
How to rename files? CompuTelSystem UNIX for Dummies Questions & Answers 9 05-14-2002 12:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2007
piltrafa's Avatar
Registered User
 

Join Date: Oct 2001
Location: Buenos Aires, Argentina
Posts: 76
rename files help

Hi, I've already search for this issue but I found different scripts for rename files, but I don't know how to customize it for my needs.
Here's what I want to do:

I have a lot of files inside many directories, like this:
/aa/01.txt
/aa/02.txt
/ab/01.txt
/ab/02.txt

I want all those files in only one directory, but I have a 01.txt file on each directory, means with the same name, so if I move all the files the last one will overwrite the one with the same name.

Because I'm a newby (and with a poor english) I've tried using something like:

find . -name '*.txt' -exec mv {}:\

but I don't know how to put a variable inside the {}.

I know a very simple script will do the trick, sadly I don't know how to do it.
Maybe you could help me with some tip. Thanks a lot!!!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-03-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
How about something like this:
Code:
$ find ./a* -type f | while read filename; do    mv ${filename} ~/tmp/dest/`echo "${filename}" | sed -e 's!/!-!g' -e 's/^.-//'`; done
This will move ./ab/01.txt to ~/tmp/dest/ab-01.txt, ./ab/02.txt to ~/tmp/dest/ab-02.txt, and so on.

Cheers
ZB
Reply With Quote
  #3 (permalink)  
Old 10-04-2007
piltrafa's Avatar
Registered User
 

Join Date: Oct 2001
Location: Buenos Aires, Argentina
Posts: 76
Excellent! Exactly what I wanted, and it works great.

Thank u for your wisdom.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0