sed Cheat Sheet
Practical sed cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
sed terminal commands productivity
sed cheat sheet with real commands and snippets for setup, core workflows, debugging, and production-safe automation patterns. If you are working across tools, pair this with the awk Cheat Sheet and npm Cheat Sheet.
Setup and Installation
Goal: Verify installation and CLI metadata
# Resolve command path from current shell
command -v sed
# Print installed version to confirm runtime
sed --version
# Read top-level help before using subcommands
sed --help
Goal: Install or upgrade the tool on a workstation
# Install package with Homebrew on macOS
brew install gnu-sed
# Upgrade to the latest available package
brew upgrade gnu-sed
# Re-check version after upgrade
sed --version
Goal: Run day-to-day commands
# Replace text in stream output
sed 's/http:/https:/g' config.txt
# Edit file in place with backup
sed -i.bak 's/DEBUG=true/DEBUG=false/g' .env
# Delete blank lines
sed '/^$/d' notes.txt
# Print selected line range
sed -n '20,40p' server.log
Core Workflows
Goal: Capture command help for quick offline lookup
# Create docs folder for generated command references
mkdir -p docs/cli
# Write help output to a timestamped file
sed --help > docs/cli/sed-help.txt
# Search help output for a keyword
rg "config|auth|deploy" docs/cli/sed-help.txt
Goal: Wrap repetitive commands in a script
# Create scripts directory for local automation
mkdir -p scripts
# Write repeatable health-check script
cat > scripts/check-sed.sh <<'SH'
#!/usr/bin/env bash
set -euo pipefail
sed --version
sed --help >/dev/null
SH
# Make script executable and run it
chmod +x scripts/check-sed.sh && ./scripts/check-sed.sh
Configuration and Environment
Goal: Pin environment variables for predictable runs
# Define environment profile for local commands
export SED_PROFILE=dev
# Persist profile in local shell configuration
echo 'export SED_PROFILE=dev' >> ~/.zshrc
# Reload shell profile changes
source ~/.zshrc
Automation and CI
Goal: Add tool checks to CI pipeline
# Run lint/test/build in strict mode
set -euo pipefail
# Verify CLI exists before invoking workflow
command -v sed
# Exit quickly if command is unavailable
sed --version
Debugging and Troubleshooting
Goal: Collect diagnostics when commands fail
# Capture command output and exit code
sed --help > /tmp/sed-debug.log 2>&1; echo $?
# Inspect captured diagnostics
tail -n 80 /tmp/sed-debug.log
# Check current shell PATH entries
echo $PATH | tr ':' '\n'
Common Gotchas
- Pin sed versions in CI so local and pipeline behavior match.
- Check tool authentication context before running write or deploy commands.
- Prefer non-interactive flags in scripts to avoid stalled jobs.
- Capture stderr logs in CI artifacts for faster incident triage.
- Keep secrets in environment variables, not committed scripts.
Related Sheets
- awk Cheat Sheet — daily awk commands and production-ready examples.
- npm Cheat Sheet — daily npm commands and production-ready examples.
- SSH Cheat Sheet — daily SSH commands and production-ready examples.
Related Cheat Sheets
awk Cheat Sheet
Practical awk cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
npm Cheat Sheet
Practical npm cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
SSH Cheat Sheet
Practical SSH cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.