Issue
I am required to fetch a value stored in a terraform file in bash script.
cat custom.tfvars
Val1 = {a1 = "12", b2 = "0.5", "count" = 2}
Val2 = {a1 = "14", b2 = "0.5", "count" = 1}
I want to write a script to fetch value of Val1(count)
.
Thanks.
Solution
sed -En '/^Val1/{s/(^.*)(count.*= )([[:digit:]]+)(.*$)/\3/p}' custom.tfvars
Enable regular expression interpretation with -E and then process lines that start with "val1" Split the line into 4 sections based on regular expressions in parenthesis and substitute the line for the 3rd section only, printing the result
Answered By - Raman Sailopal Answer Checked By - Senaida (WPSolving Volunteer)