![]() |
|
|
|
|
|||||||
| 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 |
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
-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' |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
Thank you for the advice. I will give this a try. Perl...just something else I need to study. Thanks again!
|
|||
| Google The UNIX and Linux Forums |