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
Lots of questions about linux. Methal Red Hat 1 04-25-2008 11:06 AM
renaming xls file systemsb UNIX for Dummies Questions & Answers 2 10-19-2007 07:50 AM
Help in renaming file !!! kumarsaravana_s UNIX for Dummies Questions & Answers 5 05-02-2007 12:45 PM
Deleting lots of files..... B14speedfreak UNIX for Dummies Questions & Answers 8 06-09-2006 07:47 PM
Renaming a file name dbrundrett Shell Programming and Scripting 2 01-06-2004 10:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-29-2005
AeroEngy AeroEngy is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 9
Lots of file copyingand renaming?

I have Approx 1000 files that all need to be copied from one directory to another. However, each file has to be renamed while it is copied. I have a Tab delimited text file containing all of the old and new file names (they are not all the same character length). Is there a way to read in the old and new file names from this text file into a script that can perform the copy and rename on all the .mat files in the directory.

Example of filenames.txt.
old_name1.mat newfile_name1.mat
old_name2.mat newfile_name2.mat
old_name3.mat newfile_name3.mat

Thank you in advance for any help you can give.
  #2 (permalink)  
Old 07-29-2005
piltrafa's Avatar
piltrafa piltrafa is offline
Registered User
  
 

Join Date: Oct 2001
Location: Buenos Aires, Argentina
Posts: 77
Something like this.....

for foobar in * ; do mv $foobar newfile$foobar ; done

.... could help
  #3 (permalink)  
Old 07-29-2005
AeroEngy AeroEngy is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 9
I was just giving the "newfile" as an example. Each filename is very complex (30ish characters) and the naming scheme between the old and new file is changing completely. That is why I need a script to read the first item in each line of the text file and rename it to the second item in that line then go on to the next for all 1000+ files. If it helps I could format the text file into something else like .csv or whatever.

Thanks
  #4 (permalink)  
Old 07-29-2005
fdarkangel's Avatar
fdarkangel fdarkangel is offline
Registered User
  
 

Join Date: Apr 2005
Location: /dev/null
Posts: 42
you can use sed.
it'd help if you tell what conversion you need exactly, though.
  #5 (permalink)  
Old 07-29-2005
piltrafa's Avatar
piltrafa piltrafa is offline
Registered User
  
 

Join Date: Oct 2001
Location: Buenos Aires, Argentina
Posts: 77
fdarkangel is right

use sed to read n character from each file , then put it in a variable.
For each file, reads the value from $VARIABLE and then mv to the desire pattern.

but be aware that sed could be a little bit tricky.
  #6 (permalink)  
Old 07-29-2005
AeroEngy AeroEngy is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 9
Quote:
you can use sed.
it'd help if you tell what conversion you need exactly, though.
I wish could tell you the exact file names but I can not do to the nature of the project. However, I can tell you the old name starts with the date in YYMMDD format then a _ followed by anywhere between 15 to 30 characters detailing the specifics of the file. The new naming format is totally different, different order of information and the date is pushed to the end of the name in MMDDYY format. The old and new names may or may not have the same character lengths and the character lengths vary between files. That is why I was hoping to figure out how to read in the names to a script from the text file. Since I already have a Tab delimited text file containing the old verses new names for all 1000+ files.

It will be something like this YYMMDD_LongDesciption_of_File.mat changed to Totally_different_Char_string_MMDDYY.mat about a thousand times.

Sorry about my lack of knowledge about Unix but I kind of just got thrown into full force in the last month or so. I will do some research on the sed command and try to figure out how to use it. Thanks for your help and any additional help/code anyone can give.
  #7 (permalink)  
Old 08-03-2005
phonedog365's Avatar
phonedog365 phonedog365 is offline
Registered User
  
 

Join Date: Mar 2005
Location: omaha, ne, usa
Posts: 4
wouldn't something like this work?

Code:
list=$(awk '{printf $1" "}' listfile)
for oldname in $list; do
        newname=$(grep $oldname listfile|awk '{print $2}')
        mv $oldname $newname
done
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 12:42 PM.


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