Append & Insert

Append line after match — add config after header
cat <<'EOF' > /tmp/config.conf
[network]
interface=eth0
[logging]
level=info
EOF
sed '/\[network\]/a\gateway=10.50.1.1' /tmp/config.conf
Insert line before match — add comment before directive
cat <<'EOF' > /tmp/sshd.conf
PermitRootLogin no
PasswordAuthentication yes
PubkeyAuthentication yes
EOF
sed '/PasswordAuthentication/i\# Changed 2026-04-11 per CR-2026-04-11' /tmp/sshd.conf
Replace entire line — c\ command
cat <<'EOF' > /tmp/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
sed '1c\nameserver 10.50.1.50' /tmp/resolv.conf
Read file into stream after match — r command
cat <<'EOF' > /tmp/banner.txt
============================
  AUTHORIZED ACCESS ONLY
============================
EOF
cat <<'EOF' > /tmp/sshd.conf
# SSH Configuration
Banner none
PermitRootLogin no
EOF
sed '/^Banner/r /tmp/banner.txt' /tmp/sshd.conf
Join next line — N command
cat <<'EOF' > /tmp/split.txt
Host: ise-01
  IP: 10.50.1.20
Host: ad-dc
  IP: 10.50.1.50
Host: pfsense
  IP: 10.50.1.1
EOF
sed 'N;s/\n/ /' /tmp/split.txt
Join all lines into comma-separated — classic idiom
cat <<'EOF' > /tmp/items.txt
apple
banana
cherry
date
elderberry
EOF
sed ':a;N;$!ba;s/\n/,/g' /tmp/items.txt
Append text to end of every line
cat <<'EOF' > /tmp/hosts.txt
ise-01
ad-dc
pfsense
EOF
sed 's/$/.inside.domusdigitalis.dev/' /tmp/hosts.txt
Double-space a file — insert blank line after each line
cat <<'EOF' > /tmp/compact.txt
line one
line two
line three
EOF
sed 'G' /tmp/compact.txt
Prepend line number to each line (without -n =)
cat <<'EOF' > /tmp/code.sh
#!/bin/bash
echo "hello"
exit 0
EOF
sed = /tmp/code.sh | sed 'N;s/\n/\t/'