LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2009, 09:23 AM   #1
yanchina12
LQ Newbie
 
Registered: Dec 2007
Posts: 13

Rep: Reputation: 0
Coying corresponding files


I have a folder structure where withing a parent folder called D there are 100s folders each with a name like u0001, u0002 and so on. I have two other folders names qb and kc which are outside D. Within the qb and kc folders there are corresponding files like u0001.qb and u0001.kc and so on. I'm looking for some scipts that can copy the .qb and .kc files to the corresponding folders in D. So the u0001.qb and u0001.kc files will be copied from qb and kc folders to the u0001 folders.Is there anyway that the script runs everyday automatically to update the folders? If one could help me would be obliged. Just I've been trying to help a charity.

Regarrds,
Yan
 
Old 02-24-2009, 03:08 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Pseudo code, since I don't know the exact structure of your
directory layout ...
Code:
for i in /path/to/kc/*kc
do
  targetdir=$( basename ${i} .kc )
  cp $i /path/to/${targetdir}/.
done
for i in /path/to/qb/*qb
do
  targetdir=$( basename ${i} .qb )
  cp $i /path/to/${targetdir}/.
done
 
Old 03-05-2009, 06:36 PM   #3
yanchina12
LQ Newbie
 
Registered: Dec 2007
Posts: 13

Original Poster
Rep: Reputation: 0
Dear Tinkster ,

Very kind of you for your code . I really appreciate this.Very kind of you.

The directory structure is as follows. If you please tell me where to put the path would be great!

There is a folder called D and within D there are folders with U0001,U00002......( there are 100s of folders)
There is another two folders in the same level as D called KC(contain u0001.kc, u00002 and so on) and QB (contain u0001.qb, U0002.qb and so on). So the folder D, QB and KC all are on the same level
I would like to run the script from the parent folder where is D, QB and KC exists.

In your code, please let me know where to add the path.
I really appreciate your help and would be obliged.
I'm a medic and hence I appreciate help from people like you.
 
Old 03-05-2009, 08:21 PM   #4
T74marcell
Member
 
Registered: Mar 2009
Posts: 102

Rep: Reputation: 18
The '/path/to' parts need to be replaced with your own full pathnames. Using full pathnames has the advantage that the script can run from any location (not just the parent folder), and that it also works correctly when launched by a cron job.

----------
T74marcell

Arch Linux

Last edited by T74marcell; 03-14-2009 at 01:59 AM.
 
Old 03-05-2009, 10:40 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by yanchina12 View Post
Dear Tinkster ,

Very kind of you for your code . I really appreciate this.Very kind of you.

The directory structure is as follows. If you please tell me where to put the path would be great!

There is a folder called D and within D there are folders with U0001,U00002......( there are 100s of folders)
There is another two folders in the same level as D called KC(contain u0001.kc, u00002 and so on) and QB (contain u0001.qb, U0002.qb and so on). So the folder D, QB and KC all are on the same level
I would like to run the script from the parent folder where is D, QB and KC exists.

In your code, please let me know where to add the path.
I really appreciate your help and would be obliged.
I'm a medic and hence I appreciate help from people like you.

Try this (make a back-up first ;})
Code:
#!/bin/bash
for i in KC/*kc
do
  temp=$(echo $( basename ${i} .kc ) |  tr '[a-z]' '[A-Z]' )
  target="D/${temp}/."
  cp $i ${target}
done
for i in QB/*qb
do
  temp=$(echo $( basename ${i} .qb ) |  tr '[a-z]' '[A-Z]' )
  target="D/${temp}/."
  cp $i ${target}
done
 
Old 03-06-2009, 07:19 AM   #6
yanchina12
LQ Newbie
 
Registered: Dec 2007
Posts: 13

Original Poster
Rep: Reputation: 0
Dear Tinkster,

Many thanks for the code. It gives an error `temp=$' unexpected ? Your help is appreciated. Regards, Yan
 
Old 03-06-2009, 06:59 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Try to copy and paste code; it *should* just work - it
works here. If you can't copy and paste for some reason,
make sure there's no space after the $



Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
in copy files or ls files the command want to invert select some files how to?? hocheetiong Linux - Newbie 3 06-27-2008 07:32 AM
problem in mounting cdrom(audio files running but not reading data files) amit_usual Linux - Newbie 7 12-29-2007 06:52 AM
Doom 3: Using native installer and can't locate saved game files or config files JBailey742 Linux - Games 11 08-14-2006 07:09 PM
converting a doc/ppt Windows files in html files under linux env agrosu Programming 7 02-23-2006 04:07 PM
How to filter files in files and files which are in a sub-directory with "grep"? Piero Linux - Newbie 9 08-29-2003 03:38 AM


All times are GMT -5. The time now is 12:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration