Linux - NewbieThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
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.
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.
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
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.