Issue
I have a file with the following entry:
export TF_VAR_environment_name=dev
export TF_VAR_project_name=hello-world
I would like to do 3 things with these enteries:
- Remove the export TF_VAR_ string
- Add whitespace to both sides of =
- Wrap the string right of = in " "
So my file would end up looking like:
environment_name = "dev"
project_name = "hello-world"
I'm able to remove the string with s/"export TF_VAR_"//, but haven't been able to wrap the = in whitespace, or wrap the final string in quotes. Any help would be greatly appriciated.
Is this possible to do in sed?
Solution
input.txt is your textfile. output.txt is the wanted result.
sed 's/export TF_VAR_// ; s/=\ (.*\ )$/ = "\1"/ ' < input.txt > output.txt
there is no blank between \ and (
and no blank between \ and )
Answered By - fdb Answer Checked By - Pedro (WPSolving Volunteer)