Hello,
I have the following input file:
auditing account: 3DTP (3dtp)
ERROR: S3 bucket "aws-origin-test1.3dstage.com" has policy statement with public grant: {"Sid":"PublicReadGetObject","Effect":"Allow","Principal":{"AWS":"*"},"Action":["s3:GetObject"],"Resource":["arn:aws:s3:::aws-origin-test1.3dstage.com/*"]}
auditing region: eu-west-1
auditing region: sa-east-1
auditing region: us-east-1
WARNING: instances have more than 100 security group rules: i-cf67f5b7 i-520a8436 i-1ac9477c i-42c94724 i-174ed56f i-53cfad29 i-f62d4290 i-94bf4de8 i-664ee601
ERROR: DB security group "3dstg" violates RDS policy: allows x.x.x.x/32
ERROR: DB instance "aws" is a member of DB security group "3dstg"
I want my output file to be colored based on following criteria:
If a line starts with "auditing account:" then the line should be in 'BLUE' font
If a line starts with "WARNING:" then the line should be in 'ORANGE' font
If a line starts with "ERROR:" then the line should be in 'RED' font
All other lines , the line should be in 'BLACK' font
In other words; this is how my output file should look like:
auditing account: 3DTP (3dtp)
ERROR: S3 bucket "aws-origin-test1.3dstage.com" has policy statement with public grant: {"Sid":"PublicReadGetObject","Effect":"Allow","Principal":{"AWS":"*"},"Action":["s3:GetObject"],"Resource":["arn:aws:s3:::aws-origin-test1.3dstage.com/*"]}
auditing region: eu-west-1
auditing region: sa-east-1
auditing region: us-east-1
WARNING: instances have more than 100 security group rules: i-cf67f5b7 i-520a8436 i-1ac9477c i-42c94724 i-174ed56f i-53cfad29 i-f62d4290 i-94bf4de8 i-664ee601
ERROR: DB security group "3dstg" violates RDS policy: allows x.x.x.x/32
ERROR: DB instance "aws" is a member of DB security group "3dstg"
PS: My color codes are exactly not what i want in the script; I can change them; all I need is a regular expression to match what the line starts with.
I need a small script that takes care of this:
#/bin/bash
IPfile=file.txt
OPfile-file1.txt
while read line in $IPfile
do
if [[ $line "^auditing account:" ]] ; then
echo -e "\031[0;31m'$line'\031[m \031[0;36m${0}\031[m \031[0;32m >>OPfile
elif [[ $line "^ERROR:" ]] ; then
echo -e "\033[0;31m'$line'\033[m \033[0;36m${0}\033[m \033[0;32m >>OPfile
elif [[ $line "^WARNING:" ]] ; then
echo -e "\028[0;31m'$line'\028[m \028[0;36m${0}\028[m \028[0;32m >>OPfile
else
echo -e "\029[0;31m'$line'\029[m \029[0;36m${0}\029[m \029[0;32m >>OPfile
fi
done