How to make a script that copies files from different subject folders?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








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.







share|improve this question


















  • 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














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.







share|improve this question


















  • 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












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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








edited Apr 24 at 12:28









pa4080

12k52255




12k52255










asked Apr 24 at 11:19









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 for mri_convert's syntax.
    – dessert
    Apr 24 at 13:28












  • 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







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










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





share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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





    share|improve this answer


























      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





      share|improve this answer
























        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





        share|improve this answer














        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 24 at 13:25









        dessert

        19.8k55594




        19.8k55594










        answered Apr 24 at 12:00









        pa4080

        12k52255




        12k52255



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Which professions warranted travel in Medieval times?

            How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

            Trouble downloading packages list due to a “Hash sum mismatch” error