I would like to compare two text strings if they are correct and matching provided that they are in 2 different columns in a csv file. I have the values
"DB Instance Identifier","Engine","Instance Type","MultiAZ","Reservation ID","State","Start Time","Reserved Engine","Reserved DB Instance Type"
"alpha-db-dev","postgres","db.t4g.micro",false,"alpha-db-dev-26aug2022","active","2022-08-26","postgresql","db.t4g.micro"
"alpha-db-prod","postgres","db.t4g.small",true,"alpha-db-prod-26aug2022","active","2022-08-26","postgresql","db.t4g.small"
"beta-db-dev-primary","aurora-postgresql","db.t3.medium",false,"beta-db-dev-primary-07sep2022","active","2022-09-07","postgresql","db.t3.medium"
"beta-db-dev-secondary","aurora-postgresql","db.t3.medium",false,"beta-db-dev-secondary-07sep2022","active","2022-09-07","postgresql","db.t3.small"
"charlie-db-prod","mysql","db.t3.small",true,"charlie-db-prod-07sep2022","active","2022-09-07","sql","db.t4g.medium"
in the example, the first row is a header where I would like to add the term "Engine match?" and "Instance Type Match?" which would be columns 10 and 11.
Then I would like the second row and succeeding ones to check if the value in column 2 and 8 matches. In the 2nd row and print true in column 10 if it does, and false if not.
I would also like to check if the values in column 3 and 9 are matching following the same logic above but print the result in column 11.
Desired Output:
"DB Instance Identifier","Engine","Instance Type","MultiAZ","Reservation ID","State","Start Time","Reserved Engine","Reserved DB Instance Class","Engine match?","Instance Type Match?"
"alpha-db-dev","postgres","db.t4g.micro",false,"alpha-db-dev-26aug2022","active","2022-08-26","postgresql","db.t4g.micro","true","true"
"alpha-db-prod","postgres","db.t4g.small",true,"alpha-db-prod-26aug2022","active","2022-08-26","postgresql","db.t4g.small","true","true"
"beta-db-dev-primary","aurora-postgresql","db.t3.medium",false,"beta-db-dev-primary-07sep2022","active","2022-09-07","postgresql","db.t3.medium","false","true"
"beta-db-dev-secondary","aurora-postgresql","db.t3.medium",false,"beta-db-dev-secondary-07sep2022","active","2022-09-07","postgresql","db.t3.small","true","false"
"charlie-db-prod","mysql","db.t3.small",true,"charlie-db-prod-07sep2022","active","2022-09-07","sql","db.t4g.medium","false","false"
This is a very bad attempt as I'm still learning the ropes of awk. Attempt:
NR == 1 { print $0, "\"Engine match?\",\"DB Instance Type Match?\""; next } #prints the column 10 and 11 header
{
min = $1 #skips the first line
for (i=2; i<=NF; i++) {
if ($10 != $11) { #I'm not sure how to call columns here
#I'm not sure how to put in the result true / false in column 10 and 11
}
}
print $0, min
}
Any help or idea would be great. I would also appreciate if the breakdown of the awk script would be given so I can study it further for another use case. Thanks!