所以我有这样的 .txt 文件
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
我只想grep所有以“sg”开头的值,即sg-xxxxxx。我怎样才能做到这一点?
我试过了,但是得到了很长的 sg 列表。
cat hello.txt | grep -o "sg*"
sg
sg
sg
sg
我想让每个值都以“sg”开头
像这样:
sg-77aaaa10
sg-796d1b1e
sg-79a4861d
尝试这个:
[^ ]*
表示除空格字符外。[0-9a-f]
如果您知道它们仅包含十六进制字符,您也可以使用sort -u
删除重复项sort | uniq
awk '!seen[$0]++'
sg*
表示匹配s
后跟g
零次或多次