Posts

Showing posts from July, 2019

AWS CLI - get yer mind right...

Yay! $ aws ec2 describe-subnets --region us-east-1 --query 'Subnets[*].[CidrBlock,Tags[?Key==`Name`].Value|[0]]' --output table ----------------------------------------- |            DescribeSubnets            | +-----------------+---------------------+ |  10.64.0.0/25   |  Public subnet 1    | |  10.64.2.128/25 |  Private subnet 3A  | |  10.64.1.128/25 |  Private subnet 1A  | |  10.64.1.0/25   |  Public subnet 3    | |  10.64.0.128/25 |  Public subnet 2    | |  10.64.2.0/25   |  Private subnet 2A  | +-----------------+---------------------+ WRONG WAY.... $ aws ec2 describe-subnets --region us-east-1 --query 'Subnets[*].[CidrBlock,Tags[?Key==`Name`].Value[]]' --output text ----------------------- |   DescribeSubnets   | +---------------------+ |  10...

Shell Foo - Right said sed...

Ugh.. this one was a serious PITA. For as long as I can recall, I have been using the following command $ sed -i -e 's/foo/bar/g' file.txt which would swap every occurrence of the word 'foo' with 'bar'. Today, I was attempting to swap 'MyCertificateARN' with a variable $CERTIFICATEARN $ sed -i 's/MyCertificateARN/${CERTIFICATEARN}/g' file.txt sed: -e expression #1, char 69: unknown option to `s' Huh? So, I tried substituting in other variables as a test, using actual text, swapping the ' with "... nothing was working correctly. I then echo'd the variable $ echo ${CERTIFICATEARN} arn:aws:acm:us-east-1:427832613400:certificate/57c534b7-4560-4610-a084-ad78d906d8df Wait.. there's a '/' in there.  After digging for quite a while, I discovered you can use whatever regex delimiter you want for the sed command. $ sed -i "s|MyCertificateARN|${CERTIFICATEARN}|g" ${OUTPUT}'' $ grep "...