awk/sed part of filename





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.



For example,



I have multiple files:



a.fastq.gz
b.fastq.gz
c.fastq.gz
d.fastq.gz


If I execute:



sh test.sh --INFILE b.fastq.gz


My desired output would be:



b


Something I tried and failed was,



prefix="sed 's/.fastq//' ${INFILE}"









share|improve this question































    3















    I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.



    For example,



    I have multiple files:



    a.fastq.gz
    b.fastq.gz
    c.fastq.gz
    d.fastq.gz


    If I execute:



    sh test.sh --INFILE b.fastq.gz


    My desired output would be:



    b


    Something I tried and failed was,



    prefix="sed 's/.fastq//' ${INFILE}"









    share|improve this question



























      3












      3








      3








      I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.



      For example,



      I have multiple files:



      a.fastq.gz
      b.fastq.gz
      c.fastq.gz
      d.fastq.gz


      If I execute:



      sh test.sh --INFILE b.fastq.gz


      My desired output would be:



      b


      Something I tried and failed was,



      prefix="sed 's/.fastq//' ${INFILE}"









      share|improve this question
















      I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.



      For example,



      I have multiple files:



      a.fastq.gz
      b.fastq.gz
      c.fastq.gz
      d.fastq.gz


      If I execute:



      sh test.sh --INFILE b.fastq.gz


      My desired output would be:



      b


      Something I tried and failed was,



      prefix="sed 's/.fastq//' ${INFILE}"






      awk sed command-line filenames






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 31 at 18:41









      Jesse_b

      14.4k33574




      14.4k33574










      asked Jan 31 at 18:18









      JasonJason

      255




      255






















          3 Answers
          3






          active

          oldest

          votes


















          8














          Using shell parameter expansion (assuming you are assigning your filename to INFILE):



          INFILE=b.fastq.gz
          prefix=${INFILE%%.*}


          Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):



          prefix=${INFILE%.fastq.gz}





          ${parameter%word}



          ${parameter%%word}




          The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.








          share|improve this answer


























          • sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^

            – Jason
            Jan 31 at 18:47













          • @Jason: What shell are you using?

            – Jesse_b
            Jan 31 at 18:51











          • usually bash, but the one I am currently working on is groovy.

            – Jason
            Jan 31 at 18:55











          • So your test.sh script has a hashbang that points to groovy shell? (Sorry not familiar with that one)

            – Jesse_b
            Jan 31 at 18:56






          • 2





            @Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.

            – Kusalananda
            Jan 31 at 18:57





















          7
















          Using the standard basename utility to remove the known suffix:



          $ basename b.fastq.gz .fastq.gz
          b


          With a variable:



          $ pathname="/some/path/name.fastq.gz"
          $ basename "$pathname" .fastq.gz
          name


          Assigning to a variable:



          $ prefix=$( basename "$pathname" .fastq.gz )
          $ printf 'Prefix is "%s"n' "$prefix"
          Prefix is "name"


          In a loop (over all the .fastq.gz files in the current directory):



          for filename in ./*.fastq.gz; do
          prefix=$( basename "$filename" .fastq.gz )
          # Do things using "$prefix" here
          done





          share|improve this answer


























          • I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.

            – ParanoidGeek
            Jan 31 at 18:58








          • 2





            @ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current /bin/sh implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?

            – Kusalananda
            Jan 31 at 19:01













          • @Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.

            – ParanoidGeek
            Jan 31 at 19:06



















          0














          Let me fix what you tried in steps, so you can see what you were doing:



          $ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
          sed 's/.fastq//' b.fastq.gz
          $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
          sed: can't read b.fastq.gz: No such file or directory

          $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
          b.gz
          $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
          b





          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%2f497978%2fawk-sed-part-of-filename%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            8














            Using shell parameter expansion (assuming you are assigning your filename to INFILE):



            INFILE=b.fastq.gz
            prefix=${INFILE%%.*}


            Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):



            prefix=${INFILE%.fastq.gz}





            ${parameter%word}



            ${parameter%%word}




            The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.








            share|improve this answer


























            • sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^

              – Jason
              Jan 31 at 18:47













            • @Jason: What shell are you using?

              – Jesse_b
              Jan 31 at 18:51











            • usually bash, but the one I am currently working on is groovy.

              – Jason
              Jan 31 at 18:55











            • So your test.sh script has a hashbang that points to groovy shell? (Sorry not familiar with that one)

              – Jesse_b
              Jan 31 at 18:56






            • 2





              @Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.

              – Kusalananda
              Jan 31 at 18:57


















            8














            Using shell parameter expansion (assuming you are assigning your filename to INFILE):



            INFILE=b.fastq.gz
            prefix=${INFILE%%.*}


            Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):



            prefix=${INFILE%.fastq.gz}





            ${parameter%word}



            ${parameter%%word}




            The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.








            share|improve this answer


























            • sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^

              – Jason
              Jan 31 at 18:47













            • @Jason: What shell are you using?

              – Jesse_b
              Jan 31 at 18:51











            • usually bash, but the one I am currently working on is groovy.

              – Jason
              Jan 31 at 18:55











            • So your test.sh script has a hashbang that points to groovy shell? (Sorry not familiar with that one)

              – Jesse_b
              Jan 31 at 18:56






            • 2





              @Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.

              – Kusalananda
              Jan 31 at 18:57
















            8












            8








            8







            Using shell parameter expansion (assuming you are assigning your filename to INFILE):



            INFILE=b.fastq.gz
            prefix=${INFILE%%.*}


            Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):



            prefix=${INFILE%.fastq.gz}





            ${parameter%word}



            ${parameter%%word}




            The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.








            share|improve this answer















            Using shell parameter expansion (assuming you are assigning your filename to INFILE):



            INFILE=b.fastq.gz
            prefix=${INFILE%%.*}


            Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):



            prefix=${INFILE%.fastq.gz}





            ${parameter%word}



            ${parameter%%word}




            The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.









            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 31 at 18:35

























            answered Jan 31 at 18:33









            Jesse_bJesse_b

            14.4k33574




            14.4k33574













            • sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^

              – Jason
              Jan 31 at 18:47













            • @Jason: What shell are you using?

              – Jesse_b
              Jan 31 at 18:51











            • usually bash, but the one I am currently working on is groovy.

              – Jason
              Jan 31 at 18:55











            • So your test.sh script has a hashbang that points to groovy shell? (Sorry not familiar with that one)

              – Jesse_b
              Jan 31 at 18:56






            • 2





              @Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.

              – Kusalananda
              Jan 31 at 18:57





















            • sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^

              – Jason
              Jan 31 at 18:47













            • @Jason: What shell are you using?

              – Jesse_b
              Jan 31 at 18:51











            • usually bash, but the one I am currently working on is groovy.

              – Jason
              Jan 31 at 18:55











            • So your test.sh script has a hashbang that points to groovy shell? (Sorry not familiar with that one)

              – Jesse_b
              Jan 31 at 18:56






            • 2





              @Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.

              – Kusalananda
              Jan 31 at 18:57



















            sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^

            – Jason
            Jan 31 at 18:47







            sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^

            – Jason
            Jan 31 at 18:47















            @Jason: What shell are you using?

            – Jesse_b
            Jan 31 at 18:51





            @Jason: What shell are you using?

            – Jesse_b
            Jan 31 at 18:51













            usually bash, but the one I am currently working on is groovy.

            – Jason
            Jan 31 at 18:55





            usually bash, but the one I am currently working on is groovy.

            – Jason
            Jan 31 at 18:55













            So your test.sh script has a hashbang that points to groovy shell? (Sorry not familiar with that one)

            – Jesse_b
            Jan 31 at 18:56





            So your test.sh script has a hashbang that points to groovy shell? (Sorry not familiar with that one)

            – Jesse_b
            Jan 31 at 18:56




            2




            2





            @Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.

            – Kusalananda
            Jan 31 at 18:57







            @Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.

            – Kusalananda
            Jan 31 at 18:57















            7
















            Using the standard basename utility to remove the known suffix:



            $ basename b.fastq.gz .fastq.gz
            b


            With a variable:



            $ pathname="/some/path/name.fastq.gz"
            $ basename "$pathname" .fastq.gz
            name


            Assigning to a variable:



            $ prefix=$( basename "$pathname" .fastq.gz )
            $ printf 'Prefix is "%s"n' "$prefix"
            Prefix is "name"


            In a loop (over all the .fastq.gz files in the current directory):



            for filename in ./*.fastq.gz; do
            prefix=$( basename "$filename" .fastq.gz )
            # Do things using "$prefix" here
            done





            share|improve this answer


























            • I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.

              – ParanoidGeek
              Jan 31 at 18:58








            • 2





              @ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current /bin/sh implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?

              – Kusalananda
              Jan 31 at 19:01













            • @Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.

              – ParanoidGeek
              Jan 31 at 19:06
















            7
















            Using the standard basename utility to remove the known suffix:



            $ basename b.fastq.gz .fastq.gz
            b


            With a variable:



            $ pathname="/some/path/name.fastq.gz"
            $ basename "$pathname" .fastq.gz
            name


            Assigning to a variable:



            $ prefix=$( basename "$pathname" .fastq.gz )
            $ printf 'Prefix is "%s"n' "$prefix"
            Prefix is "name"


            In a loop (over all the .fastq.gz files in the current directory):



            for filename in ./*.fastq.gz; do
            prefix=$( basename "$filename" .fastq.gz )
            # Do things using "$prefix" here
            done





            share|improve this answer


























            • I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.

              – ParanoidGeek
              Jan 31 at 18:58








            • 2





              @ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current /bin/sh implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?

              – Kusalananda
              Jan 31 at 19:01













            • @Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.

              – ParanoidGeek
              Jan 31 at 19:06














            7












            7








            7









            Using the standard basename utility to remove the known suffix:



            $ basename b.fastq.gz .fastq.gz
            b


            With a variable:



            $ pathname="/some/path/name.fastq.gz"
            $ basename "$pathname" .fastq.gz
            name


            Assigning to a variable:



            $ prefix=$( basename "$pathname" .fastq.gz )
            $ printf 'Prefix is "%s"n' "$prefix"
            Prefix is "name"


            In a loop (over all the .fastq.gz files in the current directory):



            for filename in ./*.fastq.gz; do
            prefix=$( basename "$filename" .fastq.gz )
            # Do things using "$prefix" here
            done





            share|improve this answer

















            Using the standard basename utility to remove the known suffix:



            $ basename b.fastq.gz .fastq.gz
            b


            With a variable:



            $ pathname="/some/path/name.fastq.gz"
            $ basename "$pathname" .fastq.gz
            name


            Assigning to a variable:



            $ prefix=$( basename "$pathname" .fastq.gz )
            $ printf 'Prefix is "%s"n' "$prefix"
            Prefix is "name"


            In a loop (over all the .fastq.gz files in the current directory):



            for filename in ./*.fastq.gz; do
            prefix=$( basename "$filename" .fastq.gz )
            # Do things using "$prefix" here
            done






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 31 at 19:05

























            answered Jan 31 at 18:21









            KusalanandaKusalananda

            140k17261435




            140k17261435













            • I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.

              – ParanoidGeek
              Jan 31 at 18:58








            • 2





              @ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current /bin/sh implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?

              – Kusalananda
              Jan 31 at 19:01













            • @Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.

              – ParanoidGeek
              Jan 31 at 19:06



















            • I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.

              – ParanoidGeek
              Jan 31 at 18:58








            • 2





              @ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current /bin/sh implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?

              – Kusalananda
              Jan 31 at 19:01













            • @Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.

              – ParanoidGeek
              Jan 31 at 19:06

















            I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.

            – ParanoidGeek
            Jan 31 at 18:58







            I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.

            – ParanoidGeek
            Jan 31 at 18:58






            2




            2





            @ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current /bin/sh implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?

            – Kusalananda
            Jan 31 at 19:01







            @ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current /bin/sh implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?

            – Kusalananda
            Jan 31 at 19:01















            @Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.

            – ParanoidGeek
            Jan 31 at 19:06





            @Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.

            – ParanoidGeek
            Jan 31 at 19:06











            0














            Let me fix what you tried in steps, so you can see what you were doing:



            $ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
            sed 's/.fastq//' b.fastq.gz
            $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
            sed: can't read b.fastq.gz: No such file or directory

            $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
            b.gz
            $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
            b





            share|improve this answer




























              0














              Let me fix what you tried in steps, so you can see what you were doing:



              $ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
              sed 's/.fastq//' b.fastq.gz
              $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
              sed: can't read b.fastq.gz: No such file or directory

              $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
              b.gz
              $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
              b





              share|improve this answer


























                0












                0








                0







                Let me fix what you tried in steps, so you can see what you were doing:



                $ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
                sed 's/.fastq//' b.fastq.gz
                $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
                sed: can't read b.fastq.gz: No such file or directory

                $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
                b.gz
                $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
                b





                share|improve this answer













                Let me fix what you tried in steps, so you can see what you were doing:



                $ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
                sed 's/.fastq//' b.fastq.gz
                $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
                sed: can't read b.fastq.gz: No such file or directory

                $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
                b.gz
                $ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
                b






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 31 at 23:36









                JoLJoL

                1,154412




                1,154412






























                    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%2f497978%2fawk-sed-part-of-filename%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

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith