Matching the exact string

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











up vote
2
down vote

favorite












I am extracting some data from my AWS account using AWS cli. I am not able to extract the exact string. When I am giving the following command: -



aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
'| column -t | grep production


I am getting the output as



 sftp_gateway_instance rhel production i-0aec9xxxxxxxxxxxd t2.xlarge vpc-zzzzzz1b running 2.3.4.5 3.2.1.2
abc-production-nav-1 rhel production i-0e4xxxxxxxxxxxxx3 t2.xlarge vpc-zzzzzz1b running 1.1.6.5 None
xyz-produ-nav rhel production i-0xxxxxxxxxxxxxx18 t2.xlarge vpc-zzzzzz1b running 2.8.0.4 None
solutions-production-navi centos uat i-08fffffffffff86c8 t2.large vpc-zzzzzz1b running 2.8.9.2 None


In the output provided above I don't want the last row because the production is mentioned in the name of instance not in the environment column.



I tried below awk command but in that case the output in not coming in proper column format



aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
'| awk -F ' ' '$3 == "production" print $1 "tt" $2 "t" $3"t" $4"t" $5"t" $6"t" $7"t" $8"t" $9 '


The output in this case is like below:-



abc-production centos production i-xyzabcdef t2.xlarge vpc-xyzabc running 2.18.1.0 None
doc-pdf-prod windows production i-xyzabcdef t2.large vpc-xyzabc running 172.18.70.229 None


I want the output in proper column format like the above output which i am getting using grep. Could anyone please suggest what can be done for this?







share|improve this question























    up vote
    2
    down vote

    favorite












    I am extracting some data from my AWS account using AWS cli. I am not able to extract the exact string. When I am giving the following command: -



    aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
    '| column -t | grep production


    I am getting the output as



     sftp_gateway_instance rhel production i-0aec9xxxxxxxxxxxd t2.xlarge vpc-zzzzzz1b running 2.3.4.5 3.2.1.2
    abc-production-nav-1 rhel production i-0e4xxxxxxxxxxxxx3 t2.xlarge vpc-zzzzzz1b running 1.1.6.5 None
    xyz-produ-nav rhel production i-0xxxxxxxxxxxxxx18 t2.xlarge vpc-zzzzzz1b running 2.8.0.4 None
    solutions-production-navi centos uat i-08fffffffffff86c8 t2.large vpc-zzzzzz1b running 2.8.9.2 None


    In the output provided above I don't want the last row because the production is mentioned in the name of instance not in the environment column.



    I tried below awk command but in that case the output in not coming in proper column format



    aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
    '| awk -F ' ' '$3 == "production" print $1 "tt" $2 "t" $3"t" $4"t" $5"t" $6"t" $7"t" $8"t" $9 '


    The output in this case is like below:-



    abc-production centos production i-xyzabcdef t2.xlarge vpc-xyzabc running 2.18.1.0 None
    doc-pdf-prod windows production i-xyzabcdef t2.large vpc-xyzabc running 172.18.70.229 None


    I want the output in proper column format like the above output which i am getting using grep. Could anyone please suggest what can be done for this?







    share|improve this question





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am extracting some data from my AWS account using AWS cli. I am not able to extract the exact string. When I am giving the following command: -



      aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
      '| column -t | grep production


      I am getting the output as



       sftp_gateway_instance rhel production i-0aec9xxxxxxxxxxxd t2.xlarge vpc-zzzzzz1b running 2.3.4.5 3.2.1.2
      abc-production-nav-1 rhel production i-0e4xxxxxxxxxxxxx3 t2.xlarge vpc-zzzzzz1b running 1.1.6.5 None
      xyz-produ-nav rhel production i-0xxxxxxxxxxxxxx18 t2.xlarge vpc-zzzzzz1b running 2.8.0.4 None
      solutions-production-navi centos uat i-08fffffffffff86c8 t2.large vpc-zzzzzz1b running 2.8.9.2 None


      In the output provided above I don't want the last row because the production is mentioned in the name of instance not in the environment column.



      I tried below awk command but in that case the output in not coming in proper column format



      aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
      '| awk -F ' ' '$3 == "production" print $1 "tt" $2 "t" $3"t" $4"t" $5"t" $6"t" $7"t" $8"t" $9 '


      The output in this case is like below:-



      abc-production centos production i-xyzabcdef t2.xlarge vpc-xyzabc running 2.18.1.0 None
      doc-pdf-prod windows production i-xyzabcdef t2.large vpc-xyzabc running 172.18.70.229 None


      I want the output in proper column format like the above output which i am getting using grep. Could anyone please suggest what can be done for this?







      share|improve this question











      I am extracting some data from my AWS account using AWS cli. I am not able to extract the exact string. When I am giving the following command: -



      aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
      '| column -t | grep production


      I am getting the output as



       sftp_gateway_instance rhel production i-0aec9xxxxxxxxxxxd t2.xlarge vpc-zzzzzz1b running 2.3.4.5 3.2.1.2
      abc-production-nav-1 rhel production i-0e4xxxxxxxxxxxxx3 t2.xlarge vpc-zzzzzz1b running 1.1.6.5 None
      xyz-produ-nav rhel production i-0xxxxxxxxxxxxxx18 t2.xlarge vpc-zzzzzz1b running 2.8.0.4 None
      solutions-production-navi centos uat i-08fffffffffff86c8 t2.large vpc-zzzzzz1b running 2.8.9.2 None


      In the output provided above I don't want the last row because the production is mentioned in the name of instance not in the environment column.



      I tried below awk command but in that case the output in not coming in proper column format



      aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Operating System`].Value] [0][0], [Tags[?Key==`Environment`].Value] [0][0], InstanceId, InstanceType,VpcId, State.Name, PrivateIpAddress, PublicIpAddress]
      '| awk -F ' ' '$3 == "production" print $1 "tt" $2 "t" $3"t" $4"t" $5"t" $6"t" $7"t" $8"t" $9 '


      The output in this case is like below:-



      abc-production centos production i-xyzabcdef t2.xlarge vpc-xyzabc running 2.18.1.0 None
      doc-pdf-prod windows production i-xyzabcdef t2.large vpc-xyzabc running 172.18.70.229 None


      I want the output in proper column format like the above output which i am getting using grep. Could anyone please suggest what can be done for this?









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 7 at 19:53









      Prashast

      245




      245




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Instead of grep production, which matches any line with "production" within it, use awk '$3 == "production"', which only matches lines in which the third field is "production".



          No need for anything further within the awk : by default it will then print the entire matching line.






          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%2f442393%2fmatching-the-exact-string%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










            Instead of grep production, which matches any line with "production" within it, use awk '$3 == "production"', which only matches lines in which the third field is "production".



            No need for anything further within the awk : by default it will then print the entire matching line.






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              Instead of grep production, which matches any line with "production" within it, use awk '$3 == "production"', which only matches lines in which the third field is "production".



              No need for anything further within the awk : by default it will then print the entire matching line.






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                Instead of grep production, which matches any line with "production" within it, use awk '$3 == "production"', which only matches lines in which the third field is "production".



                No need for anything further within the awk : by default it will then print the entire matching line.






                share|improve this answer













                Instead of grep production, which matches any line with "production" within it, use awk '$3 == "production"', which only matches lines in which the third field is "production".



                No need for anything further within the awk : by default it will then print the entire matching line.







                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered May 7 at 19:59









                steve

                12.1k22048




                12.1k22048






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442393%2fmatching-the-exact-string%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