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
Moving /usr ... Is this possible? FredSmith UNIX for Dummies Questions & Answers 4 08-24-2007 12:27 PM
copying/moving partition antalexi SUN Solaris 4 11-11-2006 03:59 PM
moving AIX ver 4.2.1 to another AIX box gmonix AIX 1 03-02-2006 03:36 PM
help in moving shafique UNIX for Advanced & Expert Users 5 11-20-2005 09:27 PM
moving directory bb00y High Level Programming 1 12-02-2002 08:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-29-2008
Registered User
 

Join Date: May 2008
Posts: 3
Question Copying & moving en masse

I'm new to UNIX and have got some of the basics down, but I've got a puzzle I'm having difficulty working out.

Scenario:

Have FILE_A.JPG in DIR_A

Need to copy FILE_A 200 times and rename it 200 different names. List of 200 names in NAME_FILE.TXT

After renaming 200 files, need to move each file into a specific directory based on file name.

EXAMPLE:

FILE is in CURRENT_DIR needs to move to DESTINATION_DIR

234546 is in DIR_A needs to move to DIR_B/6/46
498721 is in DIR_A needs to move to DIR_B/1/21
873489 is in DIR_A needs to move to DIR_B/9/89
459323 is in DIR_A needs to move to DIR_B/3/23

PUZZLE: How to copy & rename the 200 files and then move each file into the new destination directory?

Any recommendations for me?
Reply With Quote
Forum Sponsor
  #2  
Old 05-29-2008
Registered User
 

Join Date: May 2008
Posts: 6
I'm having trouble understanding exactly what you want... but I'll give it a shot...

cd DIR_A
for i in `cat NAME_FILE.TXT`; do dir=DIR_B/`echo $i|cut -c6`/`echo $i|cut -c5,6`; mkdir -p ../$dir; cp FILE_A.JPG ../$dir/$i;done

I have made the following assumptions:
- every file name in NAME_FILE.TXT has 6 characters
- the directory you want to create is the last charater / last 2 characters

let me know if those assumptions aren't correct...

Last edited by jimcanoa; 05-29-2008 at 07:00 PM.
Reply With Quote
  #3  
Old 05-30-2008
Registered User
 

Join Date: May 2008
Posts: 3
Quote:
Originally Posted by jimcanoa View Post

I have made the following assumptions:
- every file name in NAME_FILE.TXT has 6 characters
- the directory you want to create is the last charater / last 2 characters

let me know if those assumptions aren't correct...
Thank you for the attempt, and sorry if I wasn't very clear.

-The file names in NAME_FILE.TXT vary in character size from 4-10 characters.
-The destination directories already exist as you assumed 'character / last 2 characters'
Reply With Quote
  #4  
Old 05-30-2008
Registered User
 

Join Date: May 2008
Posts: 6
How about this, then:
Code:
for i in `cat NAME_FILE.TXT`; do size=$((`echo $i|wc -m`-1));dir=$(echo $i|cut -c$size)/$(echo $i|cut -c$(($size-1)),$size ); cp FILE_A.JPG DIR_B/$dir/$i;done
Although one liners are cool, I would do this with perl, it's just clearer
Reply With Quote
  #5  
Old 06-02-2008
Registered User
 

Join Date: May 2008
Posts: 3
Thank you for the advice. I will give this a try. Perl...just something else I need to study. Thanks again!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:03 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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0