![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lots of questions about linux. | Methal | Linux | 1 | 04-25-2008 08:06 AM |
| renaming xls file | systemsb | UNIX for Dummies Questions & Answers | 2 | 10-19-2007 04:50 AM |
| Help in renaming file !!! | kumarsaravana_s | UNIX for Dummies Questions & Answers | 5 | 05-02-2007 09:45 AM |
| Deleting lots of files..... | B14speedfreak | UNIX for Dummies Questions & Answers | 8 | 06-09-2006 04:47 PM |
| Renaming a file name | dbrundrett | Shell Programming and Scripting | 2 | 01-06-2004 06:36 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
|||
|
Quote:
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. |
|
||||
|
Try something like:
Code:
#! /usr/bin/ksh
exec < /file/with names
while read oldname newname ; do
echo cp /old/dir/$oldname /new/dir/$newname
done
exit 0
|
||||
| Google The UNIX and Linux Forums |