How to get a count of variables passed to awk

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











up vote
0
down vote

favorite












I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.



No. of variables passed to awk would be dynamic.



Below example



#!/bin/bash
NAME="Dell"
SERIAL="12345"
echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '









share|improve this question



























    up vote
    0
    down vote

    favorite












    I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.



    No. of variables passed to awk would be dynamic.



    Below example



    #!/bin/bash
    NAME="Dell"
    SERIAL="12345"
    echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.



      No. of variables passed to awk would be dynamic.



      Below example



      #!/bin/bash
      NAME="Dell"
      SERIAL="12345"
      echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '









      share|improve this question















      I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.



      No. of variables passed to awk would be dynamic.



      Below example



      #!/bin/bash
      NAME="Dell"
      SERIAL="12345"
      echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '






      bash awk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 3 mins ago

























      asked 23 mins ago









      Bharat

      3699




      3699




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          One option I can think of is to reposition those variables so they feature in ARGV. ARGC will indicate how many of them there are. Beware this make the variables unavailable in BEGIN block. You also need to account for any file names that you may be passing as parameters to awk by subtracting the number of such files from ARGC



          echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
          DELL 12345 2





          share|improve this answer






















          • ARGC should help, wondering why awk doesn't consider them as an input file
            – Bharat
            5 mins ago











          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%2f475201%2fhow-to-get-a-count-of-variables-passed-to-awk%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
          1
          down vote



          accepted










          One option I can think of is to reposition those variables so they feature in ARGV. ARGC will indicate how many of them there are. Beware this make the variables unavailable in BEGIN block. You also need to account for any file names that you may be passing as parameters to awk by subtracting the number of such files from ARGC



          echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
          DELL 12345 2





          share|improve this answer






















          • ARGC should help, wondering why awk doesn't consider them as an input file
            – Bharat
            5 mins ago















          up vote
          1
          down vote



          accepted










          One option I can think of is to reposition those variables so they feature in ARGV. ARGC will indicate how many of them there are. Beware this make the variables unavailable in BEGIN block. You also need to account for any file names that you may be passing as parameters to awk by subtracting the number of such files from ARGC



          echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
          DELL 12345 2





          share|improve this answer






















          • ARGC should help, wondering why awk doesn't consider them as an input file
            – Bharat
            5 mins ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          One option I can think of is to reposition those variables so they feature in ARGV. ARGC will indicate how many of them there are. Beware this make the variables unavailable in BEGIN block. You also need to account for any file names that you may be passing as parameters to awk by subtracting the number of such files from ARGC



          echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
          DELL 12345 2





          share|improve this answer














          One option I can think of is to reposition those variables so they feature in ARGV. ARGC will indicate how many of them there are. Beware this make the variables unavailable in BEGIN block. You also need to account for any file names that you may be passing as parameters to awk by subtracting the number of such files from ARGC



          echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
          DELL 12345 2






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 9 mins ago

























          answered 14 mins ago









          iruvar

          11.6k62959




          11.6k62959











          • ARGC should help, wondering why awk doesn't consider them as an input file
            – Bharat
            5 mins ago

















          • ARGC should help, wondering why awk doesn't consider them as an input file
            – Bharat
            5 mins ago
















          ARGC should help, wondering why awk doesn't consider them as an input file
          – Bharat
          5 mins ago





          ARGC should help, wondering why awk doesn't consider them as an input file
          – Bharat
          5 mins ago


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475201%2fhow-to-get-a-count-of-variables-passed-to-awk%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