Issue
Add comma after closing bracket }
using bash.
Using
sed 's/variable/&,/g;s/,$//'
adds comma after variable
, however,
sed 's/}/&,/g;s/,$//'
doesn't work.
Input:
variable "policy_name1" {
description = "abc xyz"
type = string
default = [
"test1"
"test2"
]
}
variable "policy_name2" {
description = "abc xyz"
type = bool
default = false
}
Output:
variable "policy_name1" {
description = "abc xyz"
type = string
default = [
"test1"
"test2"
]
},
variable "policy_name2" {
description = "abc xyz"
type = bool
default = false
}
Solution
Here is what you can do,
#!/usr/bin/env bash
FILENAME="test.tf"
COUNT=`wc -l $FILENAME | awk '{ print $1 }'`
COUNT=`expr $COUNT - 1`
sed "1,$COUNT s/}/},/" "$FILENAME"
I have provided a bash script so that we can avoid the last line in a right way. This script will append a comma whenever it finds an ending curly bracket ( } ) except for when it is last line.
Answered By - nvt_dc