Lots of file copyingand renaming?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Lots of file copyingand renaming?
# 1  
Old 07-29-2005
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  
Old 07-29-2005
Something like this.....

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

.... could help
# 3  
Old 07-29-2005
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  
Old 07-29-2005
you can use sed.
it'd help if you tell what conversion you need exactly, though.
# 5  
Old 07-29-2005
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  
Old 07-29-2005
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  
Old 07-29-2005
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

With that echo, it won't actually copy anything, it will just display what it would do if you remove the echo. So try it like that first.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove answers and explanation parts from a text file with lots of questions.?

Hi, I have a text file with thousands of questions in it. Each question (multiple lines) with multiple choice options, Answer and Explanation (optional). I need to delete Answer & explanation parts for all Questions and insert a blank line before net question. Each question starts with NO. I... (4 Replies)
Discussion started by: prvnrk
4 Replies

2. Shell Programming and Scripting

How to rename lots of files with find?

Can someone help me with this script. I have a bunch of files like this: "2209OS_02_Code" "2209OS_03_Code" "2209OS_04_Code" "2209OS_05_Code" "2209OS_06_Code" "2209OS_07_Code" "2209OS_08_Code" "2209OS_09_Code" "2209OS_10_Code" "2209OS_10_video" and I want to rename them to be like this: ... (2 Replies)
Discussion started by: siegfried
2 Replies

3. Shell Programming and Scripting

Lots of sed

Hi, I have 200 lines of sed commands in a shellscript sed s/TSTARTO2GPRSEVENTAPNACCSUM_1/TSTARTO2GPRSEVENTAPNACCSUM_24/g sed s/O2GPRSEVENTAPNACCSUM_1/O2GPRSEVENTAPNACCSUM_24/g sed s/TENDO2GPRSEVENTAPNACCSUM_1/TENDO2GPRSEVENTAPNACCSUM_24/g sed s/BSTARTO2EVENTITEM_1/BSTARTO2EVENTITEM_24/g... (6 Replies)
Discussion started by: legolad
6 Replies

4. IP Networking

netstat showing lots of errors

Hi, I have a server which receive lots of events to it and when I do netstat -Ie1000g0, I'm seeing the errors as below. Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue e1000g0 1500 abc-1.com abc-1.com 3093708246 12757 92069412 0 0 0 If anyone could direct me to right... (3 Replies)
Discussion started by: mohzub
3 Replies

5. AIX

Lots of page faults and free memory

Hello, I've been reading your forums for quite a while and the great amount of information I find here always come in hand.This time however, I need some specific help... I have a doubt with an AIX server which I'm failing to understand as I'm new to its concept of memory management... ... (8 Replies)
Discussion started by: flpgdt
8 Replies

6. Programming

problem with lots of open sockets

I'm programming in C with lots of sockets, (asynchronous handling), and for a while it goes ok, but after a while it starts to hang, or not get complete connections anymore. checking my router, i see that i get nat tables overflow and even my DNS cacher seems to be having serious issues... ... (4 Replies)
Discussion started by: alien999999999
4 Replies

7. Red Hat

Lots of questions about linux.

I am about 2 months new to Linux, and have only limited experience with PCLinuxOS, (kde) and Redhat. I am installing the latest version of PClinuxOS on my wife's PC right now but running into a problem I dont understand. I have never seen it before so i thought i'd ask how I can get around it.... (1 Reply)
Discussion started by: Methal
1 Replies

8. UNIX for Dummies Questions & Answers

Deleting lots of files.....

Hi All, Thanks in advance for reading and any posts... I have to delete a lot of files (about 6 pages of a4 (ls -ltr)) but I have to keep some as well. I would normally do an rm * to get rid of them all, but thats not what I want to do. Is there anyway I could rm * but add in a list of... (8 Replies)
Discussion started by: B14speedfreak
8 Replies
Login or Register to Ask a Question