Sed Stream Edit In Place Backup

Perform in place stream editing with sed using a backup suffix and multiple expression commands for safe text transformation.

BashCli Tooling

Code

snippet
#!/usr/bin/env bash
set -euo pipefail

FILE="config.txt"

sed -i.bak \
  -e 's/DEBUG = false/DEBUG = true/' \
  -e 's/PORT = .*/PORT = 8080/' \
  -e '/^$/d' \
  "${FILE}"

echo "Edited ${FILE}, backup at ${FILE}.bak"