Read file lines into shell line separated by spaceGrep strings in a subgroup of lines in txt fileCross fading several audio files using soxRunning a long command, split into multiple lines, in a .desktop file?Separating Commands in a Script File?Simple BASH - how to read file line by lineHow do I search for lines in a file that only contain ASCII characters and then act on them?Matching the lines that have more then one space and printing themchanging individual letter position with bash

How many US airports have 4 or more parallel runways?

Would it be possible to have a GMO that produces chocolate?

Did a flight controller ever answer Flight with a no-go?

Pythagorean triple with hypotenuse a power of 2

How to gently end involvement with an online community?

Is using a hyperlink to close a modal a poor design decision?

Is it possible to generate a leveled character in borderlands 2?

Are there any elected officials in the U.S. who are not legislators, judges, or constitutional officers?

Why would an IIS hosted site prompt for AD account credential if accessed through a hostname or IP, but not through servername?

What is a CirKle Word™?

What are some interesting features that are common cross-linguistically but don't exist in English?

Disambiguation of "nobis vobis" and "nobis nobis"

Position a tabular on the corner of a slide

Why isn't "I've" a proper response?

Does norwegian.no airline overbook flights?

Immutable builder and updater

Why in most German places is the church the tallest building?

If all stars rotate, why was there a theory developed that requires non-rotating stars?

French abbreviation for comparing two items ("vs")

Algorithms vs LP or MIP

Is “I am getting married with my sister” ambiguous?

Why do banks “park” their money at the European Central Bank?

“T” in subscript in formulas

What is the difference between Major and Minor Bug?



Read file lines into shell line separated by space


Grep strings in a subgroup of lines in txt fileCross fading several audio files using soxRunning a long command, split into multiple lines, in a .desktop file?Separating Commands in a Script File?Simple BASH - how to read file line by lineHow do I search for lines in a file that only contain ASCII characters and then act on them?Matching the lines that have more then one space and printing themchanging individual letter position with bash






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








3















I have a file called requirements.txt, each line has a package :



package1
package2
package3


I'm looking for a command that will take each line of requirements.txt and join them in one line, space separated.



So basically, I'm looking to generate the following command:



command package1 package2 package3


I tried using a for and applying command for each line of requirements.txt but it was much slower










share|improve this question
































    3















    I have a file called requirements.txt, each line has a package :



    package1
    package2
    package3


    I'm looking for a command that will take each line of requirements.txt and join them in one line, space separated.



    So basically, I'm looking to generate the following command:



    command package1 package2 package3


    I tried using a for and applying command for each line of requirements.txt but it was much slower










    share|improve this question




























      3












      3








      3


      1






      I have a file called requirements.txt, each line has a package :



      package1
      package2
      package3


      I'm looking for a command that will take each line of requirements.txt and join them in one line, space separated.



      So basically, I'm looking to generate the following command:



      command package1 package2 package3


      I tried using a for and applying command for each line of requirements.txt but it was much slower










      share|improve this question
















      I have a file called requirements.txt, each line has a package :



      package1
      package2
      package3


      I'm looking for a command that will take each line of requirements.txt and join them in one line, space separated.



      So basically, I'm looking to generate the following command:



      command package1 package2 package3


      I tried using a for and applying command for each line of requirements.txt but it was much slower







      command-line bash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 8 hours ago







      Mojimi

















      asked 9 hours ago









      MojimiMojimi

      1337 bronze badges




      1337 bronze badges























          3 Answers
          3






          active

          oldest

          votes


















          3















          You can simply use bash redirection and command substitution to get the file contents as arguments to your command:



          command $(<file)


          This works because not only space is a valid word splitting character, but newline as well – you don’t need to substitute anything. However, in the case of many lines you will get an error referring to the shell’s ARG_MAX limit (as you will with substitution solutions). Use printf to built a list of arguments and xargs to built command lines from it to work around that:



          printf "%s" $(<file) | xargs -0 command


          Note that neither of these approaches work for lines containing whitespace characters (besides the newline of course) – fortunately package names don’t.






          share|improve this answer






















          • 2





            Didn't know about it... really nice ;)

            – Ravexina
            8 hours ago


















          2















          Use tr and bash substitution:



          command $(tr 'n' ' ' < requirements.txt)


          for example:



          echo $(tr 'n' ' ' < requirements.txt)


          output would be:



          package1 package2 package3


          or:



          sudo apt install -y $(tr 'n' ' ' < requirements.txt)


          would install all packages.






          share|improve this answer

























          • That is outputting "package3xe" to me

            – Mojimi
            8 hours ago











          • What is the output of file requirements.txt?

            – Ravexina
            8 hours ago











          • ASCII text, with CRLF line terminators (This file was created in windows and sent to docker)

            – Mojimi
            8 hours ago











          • Run sudo apt install dos2unix then dos2unix requirements.txt to remove r (carriage returns) from your file it has been created on a windows machine I guess. or try $(tr 'rn' ' ') instead.

            – Ravexina
            8 hours ago












          • Figured it out, it worked with 'nr' , thanks for the hint

            – Mojimi
            8 hours ago


















          2















          You can use xargs, with the delimiter set to newline (n): this will ensure the arguments get passed correctly even if they contain whitespace:



          xargs -rd'n' command < requirements.txt





          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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1168019%2fread-file-lines-into-shell-line-separated-by-space%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









            3















            You can simply use bash redirection and command substitution to get the file contents as arguments to your command:



            command $(<file)


            This works because not only space is a valid word splitting character, but newline as well – you don’t need to substitute anything. However, in the case of many lines you will get an error referring to the shell’s ARG_MAX limit (as you will with substitution solutions). Use printf to built a list of arguments and xargs to built command lines from it to work around that:



            printf "%s" $(<file) | xargs -0 command


            Note that neither of these approaches work for lines containing whitespace characters (besides the newline of course) – fortunately package names don’t.






            share|improve this answer






















            • 2





              Didn't know about it... really nice ;)

              – Ravexina
              8 hours ago















            3















            You can simply use bash redirection and command substitution to get the file contents as arguments to your command:



            command $(<file)


            This works because not only space is a valid word splitting character, but newline as well – you don’t need to substitute anything. However, in the case of many lines you will get an error referring to the shell’s ARG_MAX limit (as you will with substitution solutions). Use printf to built a list of arguments and xargs to built command lines from it to work around that:



            printf "%s" $(<file) | xargs -0 command


            Note that neither of these approaches work for lines containing whitespace characters (besides the newline of course) – fortunately package names don’t.






            share|improve this answer






















            • 2





              Didn't know about it... really nice ;)

              – Ravexina
              8 hours ago













            3














            3










            3









            You can simply use bash redirection and command substitution to get the file contents as arguments to your command:



            command $(<file)


            This works because not only space is a valid word splitting character, but newline as well – you don’t need to substitute anything. However, in the case of many lines you will get an error referring to the shell’s ARG_MAX limit (as you will with substitution solutions). Use printf to built a list of arguments and xargs to built command lines from it to work around that:



            printf "%s" $(<file) | xargs -0 command


            Note that neither of these approaches work for lines containing whitespace characters (besides the newline of course) – fortunately package names don’t.






            share|improve this answer















            You can simply use bash redirection and command substitution to get the file contents as arguments to your command:



            command $(<file)


            This works because not only space is a valid word splitting character, but newline as well – you don’t need to substitute anything. However, in the case of many lines you will get an error referring to the shell’s ARG_MAX limit (as you will with substitution solutions). Use printf to built a list of arguments and xargs to built command lines from it to work around that:



            printf "%s" $(<file) | xargs -0 command


            Note that neither of these approaches work for lines containing whitespace characters (besides the newline of course) – fortunately package names don’t.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 8 hours ago

























            answered 8 hours ago









            dessertdessert

            28.7k6 gold badges86 silver badges119 bronze badges




            28.7k6 gold badges86 silver badges119 bronze badges










            • 2





              Didn't know about it... really nice ;)

              – Ravexina
              8 hours ago












            • 2





              Didn't know about it... really nice ;)

              – Ravexina
              8 hours ago







            2




            2





            Didn't know about it... really nice ;)

            – Ravexina
            8 hours ago





            Didn't know about it... really nice ;)

            – Ravexina
            8 hours ago













            2















            Use tr and bash substitution:



            command $(tr 'n' ' ' < requirements.txt)


            for example:



            echo $(tr 'n' ' ' < requirements.txt)


            output would be:



            package1 package2 package3


            or:



            sudo apt install -y $(tr 'n' ' ' < requirements.txt)


            would install all packages.






            share|improve this answer

























            • That is outputting "package3xe" to me

              – Mojimi
              8 hours ago











            • What is the output of file requirements.txt?

              – Ravexina
              8 hours ago











            • ASCII text, with CRLF line terminators (This file was created in windows and sent to docker)

              – Mojimi
              8 hours ago











            • Run sudo apt install dos2unix then dos2unix requirements.txt to remove r (carriage returns) from your file it has been created on a windows machine I guess. or try $(tr 'rn' ' ') instead.

              – Ravexina
              8 hours ago












            • Figured it out, it worked with 'nr' , thanks for the hint

              – Mojimi
              8 hours ago















            2















            Use tr and bash substitution:



            command $(tr 'n' ' ' < requirements.txt)


            for example:



            echo $(tr 'n' ' ' < requirements.txt)


            output would be:



            package1 package2 package3


            or:



            sudo apt install -y $(tr 'n' ' ' < requirements.txt)


            would install all packages.






            share|improve this answer

























            • That is outputting "package3xe" to me

              – Mojimi
              8 hours ago











            • What is the output of file requirements.txt?

              – Ravexina
              8 hours ago











            • ASCII text, with CRLF line terminators (This file was created in windows and sent to docker)

              – Mojimi
              8 hours ago











            • Run sudo apt install dos2unix then dos2unix requirements.txt to remove r (carriage returns) from your file it has been created on a windows machine I guess. or try $(tr 'rn' ' ') instead.

              – Ravexina
              8 hours ago












            • Figured it out, it worked with 'nr' , thanks for the hint

              – Mojimi
              8 hours ago













            2














            2










            2









            Use tr and bash substitution:



            command $(tr 'n' ' ' < requirements.txt)


            for example:



            echo $(tr 'n' ' ' < requirements.txt)


            output would be:



            package1 package2 package3


            or:



            sudo apt install -y $(tr 'n' ' ' < requirements.txt)


            would install all packages.






            share|improve this answer













            Use tr and bash substitution:



            command $(tr 'n' ' ' < requirements.txt)


            for example:



            echo $(tr 'n' ' ' < requirements.txt)


            output would be:



            package1 package2 package3


            or:



            sudo apt install -y $(tr 'n' ' ' < requirements.txt)


            would install all packages.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 8 hours ago









            RavexinaRavexina

            35.9k15 gold badges97 silver badges126 bronze badges




            35.9k15 gold badges97 silver badges126 bronze badges















            • That is outputting "package3xe" to me

              – Mojimi
              8 hours ago











            • What is the output of file requirements.txt?

              – Ravexina
              8 hours ago











            • ASCII text, with CRLF line terminators (This file was created in windows and sent to docker)

              – Mojimi
              8 hours ago











            • Run sudo apt install dos2unix then dos2unix requirements.txt to remove r (carriage returns) from your file it has been created on a windows machine I guess. or try $(tr 'rn' ' ') instead.

              – Ravexina
              8 hours ago












            • Figured it out, it worked with 'nr' , thanks for the hint

              – Mojimi
              8 hours ago

















            • That is outputting "package3xe" to me

              – Mojimi
              8 hours ago











            • What is the output of file requirements.txt?

              – Ravexina
              8 hours ago











            • ASCII text, with CRLF line terminators (This file was created in windows and sent to docker)

              – Mojimi
              8 hours ago











            • Run sudo apt install dos2unix then dos2unix requirements.txt to remove r (carriage returns) from your file it has been created on a windows machine I guess. or try $(tr 'rn' ' ') instead.

              – Ravexina
              8 hours ago












            • Figured it out, it worked with 'nr' , thanks for the hint

              – Mojimi
              8 hours ago
















            That is outputting "package3xe" to me

            – Mojimi
            8 hours ago





            That is outputting "package3xe" to me

            – Mojimi
            8 hours ago













            What is the output of file requirements.txt?

            – Ravexina
            8 hours ago





            What is the output of file requirements.txt?

            – Ravexina
            8 hours ago













            ASCII text, with CRLF line terminators (This file was created in windows and sent to docker)

            – Mojimi
            8 hours ago





            ASCII text, with CRLF line terminators (This file was created in windows and sent to docker)

            – Mojimi
            8 hours ago













            Run sudo apt install dos2unix then dos2unix requirements.txt to remove r (carriage returns) from your file it has been created on a windows machine I guess. or try $(tr 'rn' ' ') instead.

            – Ravexina
            8 hours ago






            Run sudo apt install dos2unix then dos2unix requirements.txt to remove r (carriage returns) from your file it has been created on a windows machine I guess. or try $(tr 'rn' ' ') instead.

            – Ravexina
            8 hours ago














            Figured it out, it worked with 'nr' , thanks for the hint

            – Mojimi
            8 hours ago





            Figured it out, it worked with 'nr' , thanks for the hint

            – Mojimi
            8 hours ago











            2















            You can use xargs, with the delimiter set to newline (n): this will ensure the arguments get passed correctly even if they contain whitespace:



            xargs -rd'n' command < requirements.txt





            share|improve this answer





























              2















              You can use xargs, with the delimiter set to newline (n): this will ensure the arguments get passed correctly even if they contain whitespace:



              xargs -rd'n' command < requirements.txt





              share|improve this answer



























                2














                2










                2









                You can use xargs, with the delimiter set to newline (n): this will ensure the arguments get passed correctly even if they contain whitespace:



                xargs -rd'n' command < requirements.txt





                share|improve this answer













                You can use xargs, with the delimiter set to newline (n): this will ensure the arguments get passed correctly even if they contain whitespace:



                xargs -rd'n' command < requirements.txt






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 7 hours ago









                steeldriversteeldriver

                78k12 gold badges129 silver badges209 bronze badges




                78k12 gold badges129 silver badges209 bronze badges






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • 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%2faskubuntu.com%2fquestions%2f1168019%2fread-file-lines-into-shell-line-separated-by-space%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

                    ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

                    Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

                    19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу