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.
hello everyone
first time in this forum so i hope i will explain my problem as coherent as possible
i was asked to create a loop in script which will create 5 filtered files for each file with the following freq values:
0.1
0.2
.
.
0.5
afterwards they have requested to write in the loop a command which its output needs to generate new directory for each filtered file and every new dir needs to contain the filtered file , like so:
0.1 dir contains 0.1 filtered file
0.2 dir contains 0.2 filtered file
and so on..
the script that i have used:
#!/bin/bash
file=$1
for az in `seq 0.1 0.1 0.5`
do
mkdir $az
e2proc3d.py --process=filter.lowpass.gauss.cutoff_freq=0.1 $file ${file%.mrc}.filt$az.mrc
done
can you please guide me for what's missing?
thanks for the help
Please use [CODE] tags (see my sig).
Why are you using e2proc3d.py script? Is it directly related to your question? If yes, please provide us with more details about your whole requirement.
Please paste your script output so we can know how to debug it.
this is so homework, well first things first, code tags to format your code, then steps needed to created directory by a name given using a variable then move the corresponding file(s) into same said freshly created directory.
by the use of the terms used, freq values, and filtered file. I am assuming that is just names of files using them values.
create directory with same name as file. then move same file into that directory. using the for loop in the manner you are you have no path to file, if they are in the current directory then the use of Print Working Directory (pwd)should come in handy.
for example.
Code:
for i in $(ls) ; do echo $(pwd)/$i ; done
then just incorporate that into your code to use it to move your files into the directories you've created.
Issue you cannot have two same dir and file in same parent dir as both are seen as a file in Linux. therefore you have to create the dir somewhere else then move the files into them. so the basics as I do not see exactly what your file names are. I can only guess what the look like by the code you're using to cut them up.
but this is an issue for you to figure out, this is what I'd do having unknowns.
Code:
#files in dir already
$ ls
0 0.1 0.2 0.3 0.4 0.5 1 2
#creating a variable to hold a path to
makedir="$(pwd)/sub"
$ echo $makedir
/home/userx/test/sub
#running a one liner off he cli
$ for i in `seq 0.1 0.1 0.5` ; do mkdir -p "$makedir"/"$i" ; mv -v $(pwd)/$i $makedir/$i ; done
renamed '/home/userx/test/0.1' -> '/home/userx/test/sub/0.1/0.1'
renamed '/home/userx/test/0.2' -> '/home/userx/test/sub/0.2/0.2'
renamed '/home/userx/test/0.3' -> '/home/userx/test/sub/0.3/0.3'
renamed '/home/userx/test/0.4' -> '/home/userx/test/sub/0.4/0.4'
renamed '/home/userx/test/0.5' -> '/home/userx/test/sub/0.5/0.5'
#checking results
userx@SlackOLatern.net:~/test
$ ls
0 1 2 sub
userx@SlackOLatern.net:~/test
$ ls */*
sub/0.1:
0.1
sub/0.2:
0.2
sub/0.3:
0.3
sub/0.4:
0.4
sub/0.5:
0.5
though yours might be little more complected due to I see you're cutting the name up, the basics are still the same, so you'll just need to experiment.
Please use [CODE] tags (see my sig).
Why are you using e2proc3d.py script? Is it directly related to your question? If yes, please provide us with more details about your whole requirement.
Please paste your script output so we can know how to debug it.
yes it is directly related to my question.
the output of the script should create 5 new filtered files in the current directory
in one picture there is the full script.
in the other picture is the output of the executed script.
you should see that there are "5IRZ.filt0.1.mrc" "5IRZ.filt0.2.mrc" and so on..
0.1 0.2 0.3 0.4 0.5 directories
i want to put each .mrc into its appropriate dir
5IRZ.filt0.1.mrc -> 0.1 dir
and so on
thanks
I hate photos sometimes, they are way too small. now you also need to learn how to copy, paste into code block in LQ, so everyone can read what you're reading.
look back at me post #3. you look by that code you posted to now how to cut in down to just getting the numbers off the file name, I gave you the rest already, basically.
this is so homework, well first things first, code tags to format your code, then steps needed to created directory by a name given using a variable then move the corresponding file(s) into same said freshly created directory.
by the use of the terms used, freq values, and filtered file. I am assuming that is just names of files using them values.
create directory with same name as file. then move same file into that directory. using the for loop in the manner you are you have no path to file, if they are in the current directory then the use of Print Working Directory (pwd)should come in handy.
for example.
Code:
for i in $(ls) ; do echo $(pwd)/$i ; done
then just incorporate that into your code to use it to move your files into the directories you've created.
Issue you cannot have two same dir and file in same parent dir as both are seen as a file in Linux. therefore you have to create the dir somewhere else then move the files into them. so the basics as I do not see exactly what your file names are. I can only guess what the look like by the code you're using to cut them up.
but this is an issue for you to figure out, this is what I'd do having unknowns.
Code:
#files in dir already
$ ls
0 0.1 0.2 0.3 0.4 0.5 1 2
#creating a variable to hold a path to
makedir="$(pwd)/sub"
$ echo $makedir
/home/userx/test/sub
#running a one liner off he cli
$ for i in `seq 0.1 0.1 0.5` ; do mkdir -p "$makedir"/"$i" ; mv -v $(pwd)/$i $makedir/$i ; done
renamed '/home/userx/test/0.1' -> '/home/userx/test/sub/0.1/0.1'
renamed '/home/userx/test/0.2' -> '/home/userx/test/sub/0.2/0.2'
renamed '/home/userx/test/0.3' -> '/home/userx/test/sub/0.3/0.3'
renamed '/home/userx/test/0.4' -> '/home/userx/test/sub/0.4/0.4'
renamed '/home/userx/test/0.5' -> '/home/userx/test/sub/0.5/0.5'
#checking results
userx@SlackOLatern.net:~/test
$ ls
0 1 2 sub
userx@SlackOLatern.net:~/test
$ ls */*
sub/0.1:
0.1
sub/0.2:
0.2
sub/0.3:
0.3
sub/0.4:
0.4
sub/0.5:
0.5
though yours might be little more complected due to I see you're cutting the name up, the basics are still the same, and you'll just need to experiment.
well, i have to say its hard to understand the level of scripting you used. i'm in linux class and we didnt touch this kind of level. the last part of moving the files into the dirs should be with "mv" command (i think thats what the tutor wanted)
i have tried to add this, but its a bit messy:
mv /home/emstudent/ex33/rot/5IRZ.filt0.1.mrc /home/emstudent/ex33/rot/0.1
mv /home/emstudent/ex33/rot/5IRZ.filt0.2.mrc /home/emstudent/ex33/rot/0.2
mv /home/emstudent/ex33/rot/5IRZ.filt0.3.mrc /home/emstudent/ex33/rot/0.3
mv /home/emstudent/ex33/rot/5IRZ.filt0.4.mrc /home/emstudent/ex33/rot/0.4
mv /home/emstudent/ex33/rot/5IRZ.filt0.5.mrc /home/emstudent/ex33/rot/0.5
if there is a 1-2 line command which allow me to move each file to its destined dir, that would be the best
thanks
well, i have to say its hard to understand the level of scripting you used. i'm in linux class and we didnt touch this kind of level. the last part of moving the files into the dirs should be with "mv" command (i think thats what the tutor wanted)
i have tried to add this, but its a bit messy:
mv /home/emstudent/ex33/rot/5IRZ.filt0.1.mrc /home/emstudent/ex33/rot/0.1
mv /home/emstudent/ex33/rot/5IRZ.filt0.2.mrc /home/emstudent/ex33/rot/0.2
mv /home/emstudent/ex33/rot/5IRZ.filt0.3.mrc /home/emstudent/ex33/rot/0.3
mv /home/emstudent/ex33/rot/5IRZ.filt0.4.mrc /home/emstudent/ex33/rot/0.4
mv /home/emstudent/ex33/rot/5IRZ.filt0.5.mrc /home/emstudent/ex33/rot/0.5
if there is a 1-2 line command which allow me to move each file to its destined dir, that would be the best
thanks
that is exactly what he wants, create dir by file name then move the files into the dir. like you have written there.
post your script, you already have your basic code to get what you need posted. looks like you covered variables. this is all you need to use as you are already using them along with cut command and a python script.
this here your code, is a one by one manual script, meaning you have to add the file name manually. then use $1 to get that name for processing.
Code:
#!/bin/bash
file=$1
for az in `seq 0.1 0.1 0.5`
do
mkdir $az
e2proc3d.py --process=filter.lowpass.gauss.cutoff_freq=0.1 $file ${file%.mrc}.filt$az.mrc
done
that looks to be your entire script due to the shee bang up top.
I'd used pure bash to cut the string, setup where from and where to variables to use, and one or two to hold the before name of file, and after name of file.
Knowing what you're looking for ahead of time the 0.1 - 0.5 you can cheat by setting that up to make the dir using just that information. then match the file to it then move it, or cut the part out that is 0.1 - 0.5 then use that, it is your paths needed, where are they coming from and where are you putting them that is now put into question.
how do you get them?
given your path in your post, use that.
slow down then, open a terminal then, run my code as echo so you can see what it is doing. separate them variables echo $(pwd) etc.
that is exactly what he wants, create dir by file name then move the files into the dir. like you have written there.
post your script, you already have your basic code to get what you need posted. looks like you covered variables. this is all you need to use as you are already using them along with cut command and a python script.
this here your code, is a one by one manual script, meaning you have to add the file name manually. then use $1 to get that name for processing.
Code:
#!/bin/bash
file=$1
for az in `seq 0.1 0.1 0.5`
do
mkdir $az
e2proc3d.py --process=filter.lowpass.gauss.cutoff_freq=0.1 $file ${file%.mrc}.filt$az.mrc
done
that looks to be your entire script due to the shee bang up top.
I'd used pure bash to cut the string, setup where from and where to variables to use, and one or two to hold the before name of file, and after name of file.
Knowing what you're looking for ahead of time the 0.1 - 0.5 you can cheat by setting that up to make the dir using just that information. then match the file to it then move it, or cut the part out that is 0.1 - 0.5 then use that, it is your paths needed, where are they coming from and where are you putting them that is now put into question.
how do you get them?
given your path in your post, use that.
run my code as echo so you can see what it is doing. separate them variables echo $(pwd) etc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.