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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-29-2009, 02:59 PM
|
#1
|
|
LQ Newbie
Registered: Sep 2009
Posts: 10
Rep:
|
calling director, bash script
Hello to all
I am totally new to linux and appresiate any help.
I have a bash script c2c12_4%.sh which does an iteration over my data set.
I have a main directory called 4%GXG and in that directory I have 3 sub directory (GXG_A, GXG_B, and GXG_C). In GXG_A i have 10 files (similarily with GXG_B & GXG_C), and each file has 4 sub files. The bash script is in each of the 4 directories. If i run the bash script in a terminal it iterates the data in the file and spits the output in the same file. However if I run more than one terminal it takes forever to iterate and many times crashes. I know there is an easy way as writing a loop which calls the directories and iterates the script but that is where I dont know where to start. I checked online but I couldn't find anything concrete or at least close to what I want. Do you have any ideas of how to do this.
S0 basically the following:
4%_GXG-->GXG_A, GXG_B, GXG_C----> in each (cell1 ...cell10)---> in each (A, B, C, D) ---> in each (data and bash script)
Very greatful for any help.
Best
Spinoz,
|
|
|
|
09-29-2009, 04:00 PM
|
#2
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Hi, welcome to LQ!
Sorry, but to me that description means little. Can you post
an output of
tree 4%GXG
?
Cheers,
Tink
|
|
|
|
09-29-2009, 04:50 PM
|
#3
|
|
LQ Newbie
Registered: Sep 2009
Posts: 10
Original Poster
Rep:
|
Quote:
Originally Posted by Tinkster
Hi, welcome to LQ!
Sorry, but to me that description means little. Can you post
an output of
tree 4%GXG
?
Cheers,
Tink
|
Well 4%GXG basically refers to my file directory. I just gave it a name.
So the tree looks like
4%GXG
|
|
________________________|______
| | |
plate1 plate2 plate3
| | |
| | _________|__________________
| | | | | | | | | | | |
| | c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
| _____|______________________
| | | | | | | | | | |
| c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 |
_____________|______________
| | | | | | | | | |
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
So each plate has 10 directories and within that 10 there are 4 other directories (calling it **). Each directory in ** has the bash script and the data which undergoes iteration from the script analysis.
I would like to combine this such that I tell it to go into file 4%GXG and into plate 1, c1 to c10, then into the ** and finally iterate the data in all files...after it is done it goes to plate 2, repeats everything, then plate 3.
I hope that made sense
Thank you again
|
|
|
|
09-29-2009, 05:56 PM
|
#4
|
|
Member
Registered: Sep 2009
Distribution: Fedora
Posts: 835
Rep: 
|
Quote:
Originally Posted by Spinoz
Well 4%GXG basically refers to my file directory. I just gave it a name.
So the tree looks like
4%GXG
|
|
________________________|______
| | |
plate1 plate2 plate3
| | |
| | _________|__________________
| | | | | | | | | | | |
| | c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
| _____|______________________
| | | | | | | | | | |
| c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 |
_____________|______________
| | | | | | | | | |
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
So each plate has 10 directories and within that 10 there are 4 other directories (calling it **). Each directory in ** has the bash script and the data which undergoes iteration from the script analysis.
I would like to combine this such that I tell it to go into file 4%GXG and into plate 1, c1 to c10, then into the ** and finally iterate the data in all files...after it is done it goes to plate 2, repeats everything, then plate 3.
I hope that made sense
Thank you again
|
Could you say precisely and specifically what you want the script to do? What is its purpose? Follow this recipe:
1. Here is what I hoped would happen ______________________
2. But here is what happened instead ______________________
3. Here is how (2) differs from (1) _______________________
Imagine that your post will be read by someone who doesn't already know what you want. The reason? Your post will in fact be read by someone who doesn't already know what you want.
|
|
|
|
09-29-2009, 06:48 PM
|
#5
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,973
|
A basic soln, assuming the same script is used to process all data and you pull that script out to a top level dir and there are only the dirs/files
you mentioned:
Code:
#!/bin/bash
# move to top dir; ideally supply absolute path eg /home/john/4%GXG
cd 4%GXG
# iterate plate dirs
for pdir in *
do
cd $pdir
# iterate cdirs
for cdir in *
do
cd $cdir
# iterate 4 data dirs; call them ddir
for ddir in *
do
cd $ddir
# process data files
<your data processing code goes here>
cd .. # back up to prev dir
done # end data dir
cd ..
done
cd ..
done
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
Note that your orig post seems to randomly interchange the words 'file' and 'dir', which is confusing.
HTH
Welcome to LQ

Last edited by chrism01; 09-29-2009 at 06:49 PM.
|
|
|
|
09-30-2009, 08:46 AM
|
#6
|
|
LQ Newbie
Registered: Sep 2009
Posts: 10
Original Poster
Rep:
|
Quote:
Originally Posted by chrism01
A basic soln, assuming the same script is used to process all data and you pull that script out to a top level dir and there are only the dirs/files
you mentioned:
Code:
#!/bin/bash
# move to top dir; ideally supply absolute path eg /home/john/4%GXG
cd 4%GXG
# iterate plate dirs
for pdir in *
do
cd $pdir
# iterate cdirs
for cdir in *
do
cd $cdir
# iterate 4 data dirs; call them ddir
for ddir in *
do
cd $ddir
# process data files
<your data processing code goes here>
cd .. # back up to prev dir
done # end data dir
cd ..
done
cd ..
done
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
Note that your orig post seems to randomly interchange the words 'file' and 'dir', which is confusing.
HTH
Welcome to LQ

|
Thank you kindly. The processing code is already written and saved as XYZ.sh, do you mean I should include that in the bracket?
My goal is to go into the directories and sub-sub directories and tell it to execute the following XYZ.sh file for all the sub-directories under the main directory 4%GXG.
I apologize if I was unable to be clear, my sincere apologies again.
Thank you in advance
|
|
|
|
09-30-2009, 07:23 PM
|
#7
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,973
|
Quote:
|
do you mean I should include that in the bracket?
|
No idea what you mean by that.
What I (always) suggest is to create a small test copy eg just 2 dirs at each level, and just 2 data files in each bottom dir and try a test execution.
Maybe start with just listing the filenames instead of processing them and add an
echo "in $dir"
or equiv at each level so you can see what the prog does.
With the links I supplied, you should easily be able to finish it from there.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:05 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|