How to grep all value starting with “sg” in my case

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











up vote
1
down vote

favorite












So i have this .txt file like this



TAGS aws:cloudformation:stack-name yanka-cloudformer
TAGS aws:cloudformation:logical-id WebServerSecurityGroup
SECURITYGROUPS launch-wizard-3 created 2017-04-11T15:51:41.918+09:00 sg-77aaaa10 an-dx-trainning vpc-878311e3
SECURITYGROUPS This security group was generated by AWS Marketplace and is based on recommended settin s for CentOS 6 (x86_64) - with Updates HVM version 6 2014-09-29 provided by Centos.org sg-7842031d CentOS 6 -x86_64- - with Updates HVM-6 2014-09-29-AutogenByAWSMP- 270062507952 vpc-11d10f74
SECURITYGROUPS from other cloud sg-796d1b1e rancher-demo-sg 270062507952 vpc-b4ef99d1
SECURITYGROUPS default VPC security group sg-79a4861d Cfn-Vpc-Sg-temp-SecurityGroup2DefaultSG-JLBXQ8YG4RN5 270062507952 vpc-ded6c7bb
USERIDGROUPPAIRS sg-79a4861d 270062507952


I just want to grep all value start with "sg" only which is sg-xxxxxx. How can i do that?



I tried this but what got a long list of sg.



cat hello.txt | grep -o "sg*"
sg
sg
sg
sg


I want to get every value started with "sg"



Like this:



sg-77aaaa10
sg-796d1b1e
sg-79a4861d






share|improve this question


















  • 1




    Edited my question.
    – The One
    Dec 7 '17 at 6:33














up vote
1
down vote

favorite












So i have this .txt file like this



TAGS aws:cloudformation:stack-name yanka-cloudformer
TAGS aws:cloudformation:logical-id WebServerSecurityGroup
SECURITYGROUPS launch-wizard-3 created 2017-04-11T15:51:41.918+09:00 sg-77aaaa10 an-dx-trainning vpc-878311e3
SECURITYGROUPS This security group was generated by AWS Marketplace and is based on recommended settin s for CentOS 6 (x86_64) - with Updates HVM version 6 2014-09-29 provided by Centos.org sg-7842031d CentOS 6 -x86_64- - with Updates HVM-6 2014-09-29-AutogenByAWSMP- 270062507952 vpc-11d10f74
SECURITYGROUPS from other cloud sg-796d1b1e rancher-demo-sg 270062507952 vpc-b4ef99d1
SECURITYGROUPS default VPC security group sg-79a4861d Cfn-Vpc-Sg-temp-SecurityGroup2DefaultSG-JLBXQ8YG4RN5 270062507952 vpc-ded6c7bb
USERIDGROUPPAIRS sg-79a4861d 270062507952


I just want to grep all value start with "sg" only which is sg-xxxxxx. How can i do that?



I tried this but what got a long list of sg.



cat hello.txt | grep -o "sg*"
sg
sg
sg
sg


I want to get every value started with "sg"



Like this:



sg-77aaaa10
sg-796d1b1e
sg-79a4861d






share|improve this question


















  • 1




    Edited my question.
    – The One
    Dec 7 '17 at 6:33












up vote
1
down vote

favorite









up vote
1
down vote

favorite











So i have this .txt file like this



TAGS aws:cloudformation:stack-name yanka-cloudformer
TAGS aws:cloudformation:logical-id WebServerSecurityGroup
SECURITYGROUPS launch-wizard-3 created 2017-04-11T15:51:41.918+09:00 sg-77aaaa10 an-dx-trainning vpc-878311e3
SECURITYGROUPS This security group was generated by AWS Marketplace and is based on recommended settin s for CentOS 6 (x86_64) - with Updates HVM version 6 2014-09-29 provided by Centos.org sg-7842031d CentOS 6 -x86_64- - with Updates HVM-6 2014-09-29-AutogenByAWSMP- 270062507952 vpc-11d10f74
SECURITYGROUPS from other cloud sg-796d1b1e rancher-demo-sg 270062507952 vpc-b4ef99d1
SECURITYGROUPS default VPC security group sg-79a4861d Cfn-Vpc-Sg-temp-SecurityGroup2DefaultSG-JLBXQ8YG4RN5 270062507952 vpc-ded6c7bb
USERIDGROUPPAIRS sg-79a4861d 270062507952


I just want to grep all value start with "sg" only which is sg-xxxxxx. How can i do that?



I tried this but what got a long list of sg.



cat hello.txt | grep -o "sg*"
sg
sg
sg
sg


I want to get every value started with "sg"



Like this:



sg-77aaaa10
sg-796d1b1e
sg-79a4861d






share|improve this question














So i have this .txt file like this



TAGS aws:cloudformation:stack-name yanka-cloudformer
TAGS aws:cloudformation:logical-id WebServerSecurityGroup
SECURITYGROUPS launch-wizard-3 created 2017-04-11T15:51:41.918+09:00 sg-77aaaa10 an-dx-trainning vpc-878311e3
SECURITYGROUPS This security group was generated by AWS Marketplace and is based on recommended settin s for CentOS 6 (x86_64) - with Updates HVM version 6 2014-09-29 provided by Centos.org sg-7842031d CentOS 6 -x86_64- - with Updates HVM-6 2014-09-29-AutogenByAWSMP- 270062507952 vpc-11d10f74
SECURITYGROUPS from other cloud sg-796d1b1e rancher-demo-sg 270062507952 vpc-b4ef99d1
SECURITYGROUPS default VPC security group sg-79a4861d Cfn-Vpc-Sg-temp-SecurityGroup2DefaultSG-JLBXQ8YG4RN5 270062507952 vpc-ded6c7bb
USERIDGROUPPAIRS sg-79a4861d 270062507952


I just want to grep all value start with "sg" only which is sg-xxxxxx. How can i do that?



I tried this but what got a long list of sg.



cat hello.txt | grep -o "sg*"
sg
sg
sg
sg


I want to get every value started with "sg"



Like this:



sg-77aaaa10
sg-796d1b1e
sg-79a4861d








share|improve this question













share|improve this question




share|improve this question








edited Dec 7 '17 at 6:38









Sundeep

6,9511826




6,9511826










asked Dec 7 '17 at 6:23









The One

1,01961528




1,01961528







  • 1




    Edited my question.
    – The One
    Dec 7 '17 at 6:33












  • 1




    Edited my question.
    – The One
    Dec 7 '17 at 6:33







1




1




Edited my question.
– The One
Dec 7 '17 at 6:33




Edited my question.
– The One
Dec 7 '17 at 6:33










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










Try this:



$ grep -o 'sg-[^ ]*' ip.txt
sg-77aaaa10
sg-7842031d
sg-796d1b1e
sg-79a4861d
sg-79a4861d



  • [^ ]* means other than space character. You can also use [0-9a-f] if you know they consist of only hex characters

  • pipe it to sort -u or sort | uniq or awk '!seen[$0]++' to remove duplicates


sg* means match s followed by g zero or more times






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%2f409393%2fhow-to-grep-all-value-starting-with-sg-in-my-case%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



    accepted










    Try this:



    $ grep -o 'sg-[^ ]*' ip.txt
    sg-77aaaa10
    sg-7842031d
    sg-796d1b1e
    sg-79a4861d
    sg-79a4861d



    • [^ ]* means other than space character. You can also use [0-9a-f] if you know they consist of only hex characters

    • pipe it to sort -u or sort | uniq or awk '!seen[$0]++' to remove duplicates


    sg* means match s followed by g zero or more times






    share|improve this answer
























      up vote
      3
      down vote



      accepted










      Try this:



      $ grep -o 'sg-[^ ]*' ip.txt
      sg-77aaaa10
      sg-7842031d
      sg-796d1b1e
      sg-79a4861d
      sg-79a4861d



      • [^ ]* means other than space character. You can also use [0-9a-f] if you know they consist of only hex characters

      • pipe it to sort -u or sort | uniq or awk '!seen[$0]++' to remove duplicates


      sg* means match s followed by g zero or more times






      share|improve this answer






















        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        Try this:



        $ grep -o 'sg-[^ ]*' ip.txt
        sg-77aaaa10
        sg-7842031d
        sg-796d1b1e
        sg-79a4861d
        sg-79a4861d



        • [^ ]* means other than space character. You can also use [0-9a-f] if you know they consist of only hex characters

        • pipe it to sort -u or sort | uniq or awk '!seen[$0]++' to remove duplicates


        sg* means match s followed by g zero or more times






        share|improve this answer












        Try this:



        $ grep -o 'sg-[^ ]*' ip.txt
        sg-77aaaa10
        sg-7842031d
        sg-796d1b1e
        sg-79a4861d
        sg-79a4861d



        • [^ ]* means other than space character. You can also use [0-9a-f] if you know they consist of only hex characters

        • pipe it to sort -u or sort | uniq or awk '!seen[$0]++' to remove duplicates


        sg* means match s followed by g zero or more times







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 7 '17 at 6:40









        Sundeep

        6,9511826




        6,9511826



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409393%2fhow-to-grep-all-value-starting-with-sg-in-my-case%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