How to grep all value starting with âsgâ in my case
Clash 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
sed grep
add a comment |Â
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
sed grep
1
Edited my question.
â The One
Dec 7 '17 at 6:33
add a comment |Â
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
sed grep
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
sed grep
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
add a comment |Â
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
add a comment |Â
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
orsort | uniq
orawk '!seen[$0]++'
to remove duplicates
sg*
means match s
followed by g
zero or more times
add a comment |Â
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
orsort | uniq
orawk '!seen[$0]++'
to remove duplicates
sg*
means match s
followed by g
zero or more times
add a comment |Â
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
orsort | uniq
orawk '!seen[$0]++'
to remove duplicates
sg*
means match s
followed by g
zero or more times
add a comment |Â
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
orsort | uniq
orawk '!seen[$0]++'
to remove duplicates
sg*
means match s
followed by g
zero or more times
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
orsort | uniq
orawk '!seen[$0]++'
to remove duplicates
sg*
means match s
followed by g
zero or more times
answered Dec 7 '17 at 6:40
Sundeep
6,9511826
6,9511826
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Edited my question.
â The One
Dec 7 '17 at 6:33