setting more variables insite awk if ? :

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











up vote
0
down vote

favorite












I get error in such simple test with two variables:



$ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ unterminated string
$


with single variables it works fine:



$ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:ABC
$ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:123






share|improve this question
























    up vote
    0
    down vote

    favorite












    I get error in such simple test with two variables:



    $ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
    awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
    awk: cmd. line:1: ^ syntax error
    awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
    awk: cmd. line:1: ^ syntax error
    awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
    awk: cmd. line:1: ^ unterminated string
    $


    with single variables it works fine:



    $ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
    o:ABC
    $ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
    o:123






    share|improve this question






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I get error in such simple test with two variables:



      $ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
      awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
      awk: cmd. line:1: ^ syntax error
      awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
      awk: cmd. line:1: ^ syntax error
      awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
      awk: cmd. line:1: ^ unterminated string
      $


      with single variables it works fine:



      $ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
      o:ABC
      $ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
      o:123






      share|improve this question












      I get error in such simple test with two variables:



      $ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
      awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
      awk: cmd. line:1: ^ syntax error
      awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
      awk: cmd. line:1: ^ syntax error
      awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
      awk: cmd. line:1: ^ unterminated string
      $


      with single variables it works fine:



      $ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
      o:ABC
      $ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
      o:123








      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 21:32









      DonJ

      768




      768




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          You can't really do that with the ? : operator, since it can handle a single value only, and two assignments would generate two values.



          Use an actual if statement instead:



          $ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
          o:123 r:ABC





          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%2f432941%2fsetting-more-variables-insite-awk-if%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
            3
            down vote













            You can't really do that with the ? : operator, since it can handle a single value only, and two assignments would generate two values.



            Use an actual if statement instead:



            $ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
            o:123 r:ABC





            share|improve this answer
























              up vote
              3
              down vote













              You can't really do that with the ? : operator, since it can handle a single value only, and two assignments would generate two values.



              Use an actual if statement instead:



              $ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
              o:123 r:ABC





              share|improve this answer






















                up vote
                3
                down vote










                up vote
                3
                down vote









                You can't really do that with the ? : operator, since it can handle a single value only, and two assignments would generate two values.



                Use an actual if statement instead:



                $ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
                o:123 r:ABC





                share|improve this answer












                You can't really do that with the ? : operator, since it can handle a single value only, and two assignments would generate two values.



                Use an actual if statement instead:



                $ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
                o:123 r:ABC






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 21:46









                Filipe Brandenburger

                3,461621




                3,461621






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432941%2fsetting-more-variables-insite-awk-if%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?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay