The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 07:36 PM
trying to rename the files in dir hankooknara Shell Programming and Scripting 8 07-02-2007 03:36 AM
rename many files fsmadi SUN Solaris 4 04-30-2007 11:27 AM
How to rename files? CompuTelSystem UNIX for Dummies Questions & Answers 9 05-14-2002 03:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-03-2007
piltrafa's Avatar
piltrafa piltrafa is offline
Registered User
  
 

Join Date: Oct 2001
Location: Buenos Aires, Argentina
Posts: 77
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!!!
  #2 (permalink)  
Old 10-03-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
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
  #3 (permalink)  
Old 10-04-2007
piltrafa's Avatar
piltrafa piltrafa is offline
Registered User
  
 

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

Thank u for your wisdom.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0