How to make a script that copies files from different subject folders?
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
I'm having trouble setting up a script that copies and converts files. What I basically want is a script that takes a subject e.g.
folder/subjects/subject_name/mri/norm.mgz
copies this file into
folder/investigation_folder/fs_norms/subject_name/
and converts the norm.mgz
to norm.nii
using mri_convert
, and does this with +300 subjects (in the subjects folder).
This should be fairly simple... Can anybody help me out here?
I'm a big newb! This is a example of what i would like to do - with a single subject:
mkdir /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
cp /mnt/projects/Project_folder/subjects/gXXX/mri/norm.mgz /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
mri_convert mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.mgz mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.nii
All my subjects are called g followed by 3-4 numbers. Now I need to set up a loop that does this with the +300 subjects in the /mnt/projects/Project_folder/subjects/
folder.
bash scripts
add a comment |Â
up vote
1
down vote
favorite
I'm having trouble setting up a script that copies and converts files. What I basically want is a script that takes a subject e.g.
folder/subjects/subject_name/mri/norm.mgz
copies this file into
folder/investigation_folder/fs_norms/subject_name/
and converts the norm.mgz
to norm.nii
using mri_convert
, and does this with +300 subjects (in the subjects folder).
This should be fairly simple... Can anybody help me out here?
I'm a big newb! This is a example of what i would like to do - with a single subject:
mkdir /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
cp /mnt/projects/Project_folder/subjects/gXXX/mri/norm.mgz /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
mri_convert mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.mgz mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.nii
All my subjects are called g followed by 3-4 numbers. Now I need to set up a loop that does this with the +300 subjects in the /mnt/projects/Project_folder/subjects/
folder.
bash scripts
2
You are probably right about the simplicity. Will you edit your question snow us how far you've gotten and where you're stuck? A script is a simple list of commands. Write down each command when performing the steps on one file. Then put the commands in a loop. If you get stuck, we'll help you to fix your script, but we need to know where you are stuck.
â L. D. James
Apr 24 at 11:34
See surfer.nmr.mgh.harvard.edu/fswiki/mri_convert formri_convert
's syntax.
â dessert
Apr 24 at 13:28
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm having trouble setting up a script that copies and converts files. What I basically want is a script that takes a subject e.g.
folder/subjects/subject_name/mri/norm.mgz
copies this file into
folder/investigation_folder/fs_norms/subject_name/
and converts the norm.mgz
to norm.nii
using mri_convert
, and does this with +300 subjects (in the subjects folder).
This should be fairly simple... Can anybody help me out here?
I'm a big newb! This is a example of what i would like to do - with a single subject:
mkdir /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
cp /mnt/projects/Project_folder/subjects/gXXX/mri/norm.mgz /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
mri_convert mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.mgz mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.nii
All my subjects are called g followed by 3-4 numbers. Now I need to set up a loop that does this with the +300 subjects in the /mnt/projects/Project_folder/subjects/
folder.
bash scripts
I'm having trouble setting up a script that copies and converts files. What I basically want is a script that takes a subject e.g.
folder/subjects/subject_name/mri/norm.mgz
copies this file into
folder/investigation_folder/fs_norms/subject_name/
and converts the norm.mgz
to norm.nii
using mri_convert
, and does this with +300 subjects (in the subjects folder).
This should be fairly simple... Can anybody help me out here?
I'm a big newb! This is a example of what i would like to do - with a single subject:
mkdir /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
cp /mnt/projects/Project_folder/subjects/gXXX/mri/norm.mgz /mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/
mri_convert mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.mgz mnt/projects/Project_folder/thalamic_subnuclei/fs_norms/gXXX/norm.nii
All my subjects are called g followed by 3-4 numbers. Now I need to set up a loop that does this with the +300 subjects in the /mnt/projects/Project_folder/subjects/
folder.
bash scripts
edited Apr 24 at 12:28
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
pa4080
12k52255
12k52255
asked Apr 24 at 11:19
![](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=32)
![](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=32)
Silas Nielsen
83
83
2
You are probably right about the simplicity. Will you edit your question snow us how far you've gotten and where you're stuck? A script is a simple list of commands. Write down each command when performing the steps on one file. Then put the commands in a loop. If you get stuck, we'll help you to fix your script, but we need to know where you are stuck.
â L. D. James
Apr 24 at 11:34
See surfer.nmr.mgh.harvard.edu/fswiki/mri_convert formri_convert
's syntax.
â dessert
Apr 24 at 13:28
add a comment |Â
2
You are probably right about the simplicity. Will you edit your question snow us how far you've gotten and where you're stuck? A script is a simple list of commands. Write down each command when performing the steps on one file. Then put the commands in a loop. If you get stuck, we'll help you to fix your script, but we need to know where you are stuck.
â L. D. James
Apr 24 at 11:34
See surfer.nmr.mgh.harvard.edu/fswiki/mri_convert formri_convert
's syntax.
â dessert
Apr 24 at 13:28
2
2
You are probably right about the simplicity. Will you edit your question snow us how far you've gotten and where you're stuck? A script is a simple list of commands. Write down each command when performing the steps on one file. Then put the commands in a loop. If you get stuck, we'll help you to fix your script, but we need to know where you are stuck.
â L. D. James
Apr 24 at 11:34
You are probably right about the simplicity. Will you edit your question snow us how far you've gotten and where you're stuck? A script is a simple list of commands. Write down each command when performing the steps on one file. Then put the commands in a loop. If you get stuck, we'll help you to fix your script, but we need to know where you are stuck.
â L. D. James
Apr 24 at 11:34
See surfer.nmr.mgh.harvard.edu/fswiki/mri_convert for
mri_convert
's syntax.â dessert
Apr 24 at 13:28
See surfer.nmr.mgh.harvard.edu/fswiki/mri_convert for
mri_convert
's syntax.â dessert
Apr 24 at 13:28
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Here is an example how the FOR loop can be applied within a bash script to solve this task:
#!/bin/bash
# Execute do-done inner part for each "item" under "folder/subjects/"
for subject in folder/subjects/*
do
# Check whether the source file exists
if [[ -f $subject/mri/norm.mgz ]]
then
# $subject##*/ will cut the parent path from the value of the variable '$subject'
echo "Processing: $subject##*/"
# Create the new subject directory
mkdir -p "folder/investigation_folder/fs_norms/$subject##*/"
# Copy the .mgz file into the new directory
cp "$subject/mri/norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//"
# Do the conversion to .nii (I'm not sure this is the correct syntax of mri_convert that you are using)
mri_convert "folder/investigation_folder/fs_norms/$subject##*//norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//norm.nii"
fi
done
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Here is an example how the FOR loop can be applied within a bash script to solve this task:
#!/bin/bash
# Execute do-done inner part for each "item" under "folder/subjects/"
for subject in folder/subjects/*
do
# Check whether the source file exists
if [[ -f $subject/mri/norm.mgz ]]
then
# $subject##*/ will cut the parent path from the value of the variable '$subject'
echo "Processing: $subject##*/"
# Create the new subject directory
mkdir -p "folder/investigation_folder/fs_norms/$subject##*/"
# Copy the .mgz file into the new directory
cp "$subject/mri/norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//"
# Do the conversion to .nii (I'm not sure this is the correct syntax of mri_convert that you are using)
mri_convert "folder/investigation_folder/fs_norms/$subject##*//norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//norm.nii"
fi
done
add a comment |Â
up vote
2
down vote
accepted
Here is an example how the FOR loop can be applied within a bash script to solve this task:
#!/bin/bash
# Execute do-done inner part for each "item" under "folder/subjects/"
for subject in folder/subjects/*
do
# Check whether the source file exists
if [[ -f $subject/mri/norm.mgz ]]
then
# $subject##*/ will cut the parent path from the value of the variable '$subject'
echo "Processing: $subject##*/"
# Create the new subject directory
mkdir -p "folder/investigation_folder/fs_norms/$subject##*/"
# Copy the .mgz file into the new directory
cp "$subject/mri/norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//"
# Do the conversion to .nii (I'm not sure this is the correct syntax of mri_convert that you are using)
mri_convert "folder/investigation_folder/fs_norms/$subject##*//norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//norm.nii"
fi
done
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Here is an example how the FOR loop can be applied within a bash script to solve this task:
#!/bin/bash
# Execute do-done inner part for each "item" under "folder/subjects/"
for subject in folder/subjects/*
do
# Check whether the source file exists
if [[ -f $subject/mri/norm.mgz ]]
then
# $subject##*/ will cut the parent path from the value of the variable '$subject'
echo "Processing: $subject##*/"
# Create the new subject directory
mkdir -p "folder/investigation_folder/fs_norms/$subject##*/"
# Copy the .mgz file into the new directory
cp "$subject/mri/norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//"
# Do the conversion to .nii (I'm not sure this is the correct syntax of mri_convert that you are using)
mri_convert "folder/investigation_folder/fs_norms/$subject##*//norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//norm.nii"
fi
done
Here is an example how the FOR loop can be applied within a bash script to solve this task:
#!/bin/bash
# Execute do-done inner part for each "item" under "folder/subjects/"
for subject in folder/subjects/*
do
# Check whether the source file exists
if [[ -f $subject/mri/norm.mgz ]]
then
# $subject##*/ will cut the parent path from the value of the variable '$subject'
echo "Processing: $subject##*/"
# Create the new subject directory
mkdir -p "folder/investigation_folder/fs_norms/$subject##*/"
# Copy the .mgz file into the new directory
cp "$subject/mri/norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//"
# Do the conversion to .nii (I'm not sure this is the correct syntax of mri_convert that you are using)
mri_convert "folder/investigation_folder/fs_norms/$subject##*//norm.mgz" "folder/investigation_folder/fs_norms/$subject##*//norm.nii"
fi
done
edited Apr 24 at 13:25
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
dessert
19.8k55594
19.8k55594
answered Apr 24 at 12:00
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
pa4080
12k52255
12k52255
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1027771%2fhow-to-make-a-script-that-copies-files-from-different-subject-folders%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
You are probably right about the simplicity. Will you edit your question snow us how far you've gotten and where you're stuck? A script is a simple list of commands. Write down each command when performing the steps on one file. Then put the commands in a loop. If you get stuck, we'll help you to fix your script, but we need to know where you are stuck.
â L. D. James
Apr 24 at 11:34
See surfer.nmr.mgh.harvard.edu/fswiki/mri_convert for
mri_convert
's syntax.â dessert
Apr 24 at 13:28