Improved SED commands

This commit is contained in:
Michele Cereda
2022-09-07 12:54:38 +02:00
parent c4c99f0610
commit 38940ffc42
2 changed files with 22 additions and 2 deletions

View File

@@ -4,11 +4,19 @@
```sh
# Delete lines matching "OAM" from a file.
sed -e '/OAM/d' -i .bash_history
# Overwrite the source file with the changes.
sed '/OAM/d' -i .bash_history
# Change fstab entries.
# Show changed fstab entries.
# Don't save the changes.
sed /etc/fstab \
-e "s|#.*\s*/boot\s*.*|/dev/sda1 /boot vfat defaults 0 0|" \
-e "s|#.*\s*ext4\s*.*|/dev/sda2 / btrfs compress-force=zstd 0 0|" \
-e '/#.*\s*swap\s*.*/d'
```
## Further readings
- [GNU SED Online Tester]
[gnu sed online tester]: https://sed.js.org/

View File

@@ -164,14 +164,26 @@ resource "azurerm_key_vault_key" "key" {
}
```
### Export the contents of a tfvars file as shell variables
```sh
# As normal shell variables.
eval "export $(sed -E 's/[[:blank:]]*//g' file.tfvars)"
# As TF shell variables (TF_VAR_*).
eval "export $(sed -E 's/([[:graph:]]+)[[:blank:]]*=[[:blank:]]*([[:graph:]]+)/TF_VAR_\1=\2/' file.tfvars)"
```
## Further readings
- [CLI Documentation]
- [Providers best practices]
- [Version constraints]
- [References to Named Values]
- [Environment Variables]
[cli documentation]: https://www.terraform.io/docs/cli/
[environment variables]: https://www.terraform.io/cli/config/environment-variables
[providers best practices]: https://www.terraform.io/language/providers/requirements#best-practices-for-provider-versions
[references to named values]: https://www.terraform.io/language/expressions/references
[version constraints]: https://www.terraform.io/language/expressions/version-constraints