bash script split file names












0















I have the following bash script:



#!/bin/bash

for r in $(find . -name "*.fastq");
do

cat <<EOF
#qsub <<EOF
#!/bin/bash -l

#PBS -N $r

EOF

done


Unfortunately, all filename get split:



> sh  cFiltering_pbs.sh 
#qsub <<EOF
#!/bin/bash -l

#PBS -N ./76A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq

#qsub <<EOF
#!/bin/bash -l

#PBS -N ./104A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq


Here is the find output:



find . -name "*.fastq"
./76A Paired.fastq
./104A Paired.fastq


What did I miss?










share|improve this question


















  • 5





    for r in $(find . -name "*.fastq"); is pretty bad...

    – don_crissti
    3 hours ago






  • 1





    Are all your fastq files in the same directory?

    – roaima
    3 hours ago











  • yes, they're all in the same directory. I solved it with this unix.stackexchange.com/a/9499/34872

    – user977828
    2 hours ago











  • That's a poor solution for your situation

    – roaima
    2 hours ago






  • 2





    see: Why does my shell script choke on whitespace or other special characters? and Recursively iterate through files in a directory and also mywiki.wooledge.org/WordSplitting

    – ilkkachu
    2 hours ago


















0















I have the following bash script:



#!/bin/bash

for r in $(find . -name "*.fastq");
do

cat <<EOF
#qsub <<EOF
#!/bin/bash -l

#PBS -N $r

EOF

done


Unfortunately, all filename get split:



> sh  cFiltering_pbs.sh 
#qsub <<EOF
#!/bin/bash -l

#PBS -N ./76A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq

#qsub <<EOF
#!/bin/bash -l

#PBS -N ./104A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq


Here is the find output:



find . -name "*.fastq"
./76A Paired.fastq
./104A Paired.fastq


What did I miss?










share|improve this question


















  • 5





    for r in $(find . -name "*.fastq"); is pretty bad...

    – don_crissti
    3 hours ago






  • 1





    Are all your fastq files in the same directory?

    – roaima
    3 hours ago











  • yes, they're all in the same directory. I solved it with this unix.stackexchange.com/a/9499/34872

    – user977828
    2 hours ago











  • That's a poor solution for your situation

    – roaima
    2 hours ago






  • 2





    see: Why does my shell script choke on whitespace or other special characters? and Recursively iterate through files in a directory and also mywiki.wooledge.org/WordSplitting

    – ilkkachu
    2 hours ago
















0












0








0








I have the following bash script:



#!/bin/bash

for r in $(find . -name "*.fastq");
do

cat <<EOF
#qsub <<EOF
#!/bin/bash -l

#PBS -N $r

EOF

done


Unfortunately, all filename get split:



> sh  cFiltering_pbs.sh 
#qsub <<EOF
#!/bin/bash -l

#PBS -N ./76A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq

#qsub <<EOF
#!/bin/bash -l

#PBS -N ./104A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq


Here is the find output:



find . -name "*.fastq"
./76A Paired.fastq
./104A Paired.fastq


What did I miss?










share|improve this question














I have the following bash script:



#!/bin/bash

for r in $(find . -name "*.fastq");
do

cat <<EOF
#qsub <<EOF
#!/bin/bash -l

#PBS -N $r

EOF

done


Unfortunately, all filename get split:



> sh  cFiltering_pbs.sh 
#qsub <<EOF
#!/bin/bash -l

#PBS -N ./76A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq

#qsub <<EOF
#!/bin/bash -l

#PBS -N ./104A

#qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq


Here is the find output:



find . -name "*.fastq"
./76A Paired.fastq
./104A Paired.fastq


What did I miss?







bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









user977828user977828

3471516




3471516








  • 5





    for r in $(find . -name "*.fastq"); is pretty bad...

    – don_crissti
    3 hours ago






  • 1





    Are all your fastq files in the same directory?

    – roaima
    3 hours ago











  • yes, they're all in the same directory. I solved it with this unix.stackexchange.com/a/9499/34872

    – user977828
    2 hours ago











  • That's a poor solution for your situation

    – roaima
    2 hours ago






  • 2





    see: Why does my shell script choke on whitespace or other special characters? and Recursively iterate through files in a directory and also mywiki.wooledge.org/WordSplitting

    – ilkkachu
    2 hours ago
















  • 5





    for r in $(find . -name "*.fastq"); is pretty bad...

    – don_crissti
    3 hours ago






  • 1





    Are all your fastq files in the same directory?

    – roaima
    3 hours ago











  • yes, they're all in the same directory. I solved it with this unix.stackexchange.com/a/9499/34872

    – user977828
    2 hours ago











  • That's a poor solution for your situation

    – roaima
    2 hours ago






  • 2





    see: Why does my shell script choke on whitespace or other special characters? and Recursively iterate through files in a directory and also mywiki.wooledge.org/WordSplitting

    – ilkkachu
    2 hours ago










5




5





for r in $(find . -name "*.fastq"); is pretty bad...

– don_crissti
3 hours ago





for r in $(find . -name "*.fastq"); is pretty bad...

– don_crissti
3 hours ago




1




1





Are all your fastq files in the same directory?

– roaima
3 hours ago





Are all your fastq files in the same directory?

– roaima
3 hours ago













yes, they're all in the same directory. I solved it with this unix.stackexchange.com/a/9499/34872

– user977828
2 hours ago





yes, they're all in the same directory. I solved it with this unix.stackexchange.com/a/9499/34872

– user977828
2 hours ago













That's a poor solution for your situation

– roaima
2 hours ago





That's a poor solution for your situation

– roaima
2 hours ago




2




2





see: Why does my shell script choke on whitespace or other special characters? and Recursively iterate through files in a directory and also mywiki.wooledge.org/WordSplitting

– ilkkachu
2 hours ago







see: Why does my shell script choke on whitespace or other special characters? and Recursively iterate through files in a directory and also mywiki.wooledge.org/WordSplitting

– ilkkachu
2 hours ago












1 Answer
1






active

oldest

votes


















1














Instead of using find you can simply loop through the files themselves. Notice that I have double-quoted "$r"; you need to do that to keep the space in the filenames intact and unparsed by the shell.



for r in *.fastq
do
# Stuff using "$r"...
:
done





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495186%2fbash-script-split-file-names%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Instead of using find you can simply loop through the files themselves. Notice that I have double-quoted "$r"; you need to do that to keep the space in the filenames intact and unparsed by the shell.



    for r in *.fastq
    do
    # Stuff using "$r"...
    :
    done





    share|improve this answer




























      1














      Instead of using find you can simply loop through the files themselves. Notice that I have double-quoted "$r"; you need to do that to keep the space in the filenames intact and unparsed by the shell.



      for r in *.fastq
      do
      # Stuff using "$r"...
      :
      done





      share|improve this answer


























        1












        1








        1







        Instead of using find you can simply loop through the files themselves. Notice that I have double-quoted "$r"; you need to do that to keep the space in the filenames intact and unparsed by the shell.



        for r in *.fastq
        do
        # Stuff using "$r"...
        :
        done





        share|improve this answer













        Instead of using find you can simply loop through the files themselves. Notice that I have double-quoted "$r"; you need to do that to keep the space in the filenames intact and unparsed by the shell.



        for r in *.fastq
        do
        # Stuff using "$r"...
        :
        done






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        roaimaroaima

        43.4k553116




        43.4k553116






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495186%2fbash-script-split-file-names%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Entries order in /etc/network/interfaces

            新発田市

            Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)