Matching the exact string
Clash 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?
linux shell awk grep aws
add a comment |Â
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?
linux shell awk grep aws
add a comment |Â
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?
linux shell awk grep aws
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?
linux shell awk grep aws
asked May 7 at 19:53
Prashast
245
245
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered May 7 at 19:59
steve
12.1k22048
12.1k22048
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%2f442393%2fmatching-the-exact-string%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