Have xargs pass a flag from stdin instead of command parameter

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











up vote
0
down vote

favorite












Given an application, myApplication, that streams lines to stdout



$ myApplication
flag1
flag2
flag3


How do I use xargs to pass those values as flags to a command instead of passing them as parameters?



For example, the resulting invocations should be:



anotherApplication --flag "flag1" parameterNotFromXargs
anotherApplication --flag "flag2" parameterNotFromXargs
anotherApplication --flag "flag3" parameterNotFromXargs


My failed attempt using the -I option produced the wrong output:



$ myApplication | xargs -L1 -I % echo "e: %"
e: %
e: %
e: %









share|improve this question

















  • 1




    What OS are you running? What version of xargs?
    – ilkkachu
    Sep 13 at 17:08














up vote
0
down vote

favorite












Given an application, myApplication, that streams lines to stdout



$ myApplication
flag1
flag2
flag3


How do I use xargs to pass those values as flags to a command instead of passing them as parameters?



For example, the resulting invocations should be:



anotherApplication --flag "flag1" parameterNotFromXargs
anotherApplication --flag "flag2" parameterNotFromXargs
anotherApplication --flag "flag3" parameterNotFromXargs


My failed attempt using the -I option produced the wrong output:



$ myApplication | xargs -L1 -I % echo "e: %"
e: %
e: %
e: %









share|improve this question

















  • 1




    What OS are you running? What version of xargs?
    – ilkkachu
    Sep 13 at 17:08












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Given an application, myApplication, that streams lines to stdout



$ myApplication
flag1
flag2
flag3


How do I use xargs to pass those values as flags to a command instead of passing them as parameters?



For example, the resulting invocations should be:



anotherApplication --flag "flag1" parameterNotFromXargs
anotherApplication --flag "flag2" parameterNotFromXargs
anotherApplication --flag "flag3" parameterNotFromXargs


My failed attempt using the -I option produced the wrong output:



$ myApplication | xargs -L1 -I % echo "e: %"
e: %
e: %
e: %









share|improve this question













Given an application, myApplication, that streams lines to stdout



$ myApplication
flag1
flag2
flag3


How do I use xargs to pass those values as flags to a command instead of passing them as parameters?



For example, the resulting invocations should be:



anotherApplication --flag "flag1" parameterNotFromXargs
anotherApplication --flag "flag2" parameterNotFromXargs
anotherApplication --flag "flag3" parameterNotFromXargs


My failed attempt using the -I option produced the wrong output:



$ myApplication | xargs -L1 -I % echo "e: %"
e: %
e: %
e: %






pipe xargs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 13 at 17:01









Ramon J Romero y Vigil

1256




1256







  • 1




    What OS are you running? What version of xargs?
    – ilkkachu
    Sep 13 at 17:08












  • 1




    What OS are you running? What version of xargs?
    – ilkkachu
    Sep 13 at 17:08







1




1




What OS are you running? What version of xargs?
– ilkkachu
Sep 13 at 17:08




What OS are you running? What version of xargs?
– ilkkachu
Sep 13 at 17:08










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Unable to replicate:



$ echo -e "onentwonthree" | xargs -L1 -I% echo "I was told % times"
I was told one times
I was told two times
I was told three times


If myApplication is returning its output on standard input, the above invocation of xargs should work properly. If the output you are seeing is actually standard error, you need to redirect that to standard output with myApplication 2>&1.






share|improve this answer



























    up vote
    0
    down vote













    The easiest way is a script



    #!/bin/sh
    anotherApplication --flag "$1" parameterNotFromXargs


    And call it with



    myApplication | xargs -L1 ./myscript.sh


    If you want to avoid the script, you can use give the command inline:



    myApplication | xargs -L1 sh -c 'anotherApplication --flag "$1" parameterNotFromXargs' _





    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',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      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%2funix.stackexchange.com%2fquestions%2f468844%2fhave-xargs-pass-a-flag-from-stdin-instead-of-command-parameter%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      Unable to replicate:



      $ echo -e "onentwonthree" | xargs -L1 -I% echo "I was told % times"
      I was told one times
      I was told two times
      I was told three times


      If myApplication is returning its output on standard input, the above invocation of xargs should work properly. If the output you are seeing is actually standard error, you need to redirect that to standard output with myApplication 2>&1.






      share|improve this answer
























        up vote
        0
        down vote













        Unable to replicate:



        $ echo -e "onentwonthree" | xargs -L1 -I% echo "I was told % times"
        I was told one times
        I was told two times
        I was told three times


        If myApplication is returning its output on standard input, the above invocation of xargs should work properly. If the output you are seeing is actually standard error, you need to redirect that to standard output with myApplication 2>&1.






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          Unable to replicate:



          $ echo -e "onentwonthree" | xargs -L1 -I% echo "I was told % times"
          I was told one times
          I was told two times
          I was told three times


          If myApplication is returning its output on standard input, the above invocation of xargs should work properly. If the output you are seeing is actually standard error, you need to redirect that to standard output with myApplication 2>&1.






          share|improve this answer












          Unable to replicate:



          $ echo -e "onentwonthree" | xargs -L1 -I% echo "I was told % times"
          I was told one times
          I was told two times
          I was told three times


          If myApplication is returning its output on standard input, the above invocation of xargs should work properly. If the output you are seeing is actually standard error, you need to redirect that to standard output with myApplication 2>&1.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 13 at 17:06









          DopeGhoti

          41.3k55180




          41.3k55180






















              up vote
              0
              down vote













              The easiest way is a script



              #!/bin/sh
              anotherApplication --flag "$1" parameterNotFromXargs


              And call it with



              myApplication | xargs -L1 ./myscript.sh


              If you want to avoid the script, you can use give the command inline:



              myApplication | xargs -L1 sh -c 'anotherApplication --flag "$1" parameterNotFromXargs' _





              share|improve this answer
























                up vote
                0
                down vote













                The easiest way is a script



                #!/bin/sh
                anotherApplication --flag "$1" parameterNotFromXargs


                And call it with



                myApplication | xargs -L1 ./myscript.sh


                If you want to avoid the script, you can use give the command inline:



                myApplication | xargs -L1 sh -c 'anotherApplication --flag "$1" parameterNotFromXargs' _





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  The easiest way is a script



                  #!/bin/sh
                  anotherApplication --flag "$1" parameterNotFromXargs


                  And call it with



                  myApplication | xargs -L1 ./myscript.sh


                  If you want to avoid the script, you can use give the command inline:



                  myApplication | xargs -L1 sh -c 'anotherApplication --flag "$1" parameterNotFromXargs' _





                  share|improve this answer












                  The easiest way is a script



                  #!/bin/sh
                  anotherApplication --flag "$1" parameterNotFromXargs


                  And call it with



                  myApplication | xargs -L1 ./myscript.sh


                  If you want to avoid the script, you can use give the command inline:



                  myApplication | xargs -L1 sh -c 'anotherApplication --flag "$1" parameterNotFromXargs' _






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 13 at 17:24









                  RalfFriedl

                  4,1251625




                  4,1251625



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468844%2fhave-xargs-pass-a-flag-from-stdin-instead-of-command-parameter%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?