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.
Code
#!/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"Report a problem with this exampleOpens a pre-filled issue on GitHub.